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;
^~~~~~
This commit is contained in:
+12
-12
@@ -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;
|
||||
}
|
||||
|
||||
l[++i] = strdup(b);
|
||||
if (!l[i]) {
|
||||
strv_free(l);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user