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

2012-10-25 Thread Michal Sekletar
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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 16700fe..2f0f6ee 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;
+char **i;
 
 keymaps = set_new(string_hash_func, string_compare_func);
 if (!keymaps)
-- 
1.7.11.7

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


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

2012-10-25 Thread Michal Schmidt

Dne 25.10.2012 16:16, Michal Sekletar napsal(a):

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 | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 16700fe..2f0f6ee 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;
+char **i;

  keymaps = set_new(string_hash_func, string_compare_func);
  if (!keymaps)



When using _cleanup_strv_free you must initialize l to NULL.
Also you forgot that there's one explicit strv_free(l) in the function. 
That would result in freeing it twice.


Michal

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel