diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-10-11 19:33:20 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-10-13 17:56:54 -0400 |
commit | 74dcc2df7b2a340c3e1fe9e61e5c8deb324c83d7 (patch) | |
tree | 345df2cb8f2a093d36d84a24e21716577c0aea49 /src/shared/dbus-common.c | |
parent | b47d419c25ecc735615a1088060c1ec8bef1e41f (diff) |
dbus-common: avoid leak in error path
src/shared/dbus-common.c:968:33: warning: Potential leak of memory pointed to by 'l'
return -EINVAL;
^~~~~~
Diffstat (limited to 'src/shared/dbus-common.c')
-rw-r--r-- | src/shared/dbus-common.c | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c index c727cae7cd..3ba2d87c4d 100644 --- a/src/shared/dbus-common.c +++ b/src/shared/dbus-common.c @@ -934,7 +934,7 @@ int bus_parse_strv_iter(DBusMessageIter *iter, char ***_l) { int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) { DBusMessageIter sub, sub2; unsigned n = 0, i = 0; - char **l; + _cleanup_strv_free_ char **l = NULL; assert(iter); assert(_l); @@ -953,6 +953,7 @@ int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) { l = new(char*, n*2+1); if (!l) return -ENOMEM; + l[0] = NULL; /* make sure that l is properly terminated at all times */ dbus_message_iter_recurse(iter, &sub); @@ -968,26 +969,25 @@ int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) { return -EINVAL; l[i] = strdup(a); - if (!l[i]) { - strv_free(l); + if (!l[i]) return -ENOMEM; - } + i++; - l[++i] = strdup(b); - if (!l[i]) { - strv_free(l); + l[i] = strdup(b); + if (!l[i]) return -ENOMEM; - } - i++; + dbus_message_iter_next(&sub); } assert(i == n*2); l[i] = NULL; - if (_l) + if (_l) { *_l = l; + l = NULL; /* avoid freeing */ + } return 0; } |