[systemd-devel] [PATCH 3/5] localectl: fix memleak, use _cleanup_strv_free_

Michal Sekletar msekleta at redhat.com
Fri Oct 26 05:16:18 PDT 2012


l might contain zero strings, however there is still memory
allocated for NULL terminator, use _cleanup_strv_free_ instead to
prevent tiny leak in such case.
---
 src/locale/localectl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 84feb25..7d3ac0a 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -483,7 +483,8 @@ static int nftw_cb(
 }
 
 static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
-        char **l, **i;
+        char _cleanup_strv_free_ **l = NULL;
+        char **i;
 
         keymaps = set_new(string_hash_func, string_compare_func);
         if (!keymaps)
@@ -513,7 +514,6 @@ static int list_vconsole_keymaps(DBusConnection *bus, char **args, unsigned n) {
         STRV_FOREACH(i, l)
                 puts(*i);
 
-        strv_free(l);
 
         return 0;
 }
-- 
1.7.11.7



More information about the systemd-devel mailing list