|
|
65878a |
From 10725a4ee35e5d1d97c2f9bc72010c5c0210cd6b Mon Sep 17 00:00:00 2001
|
|
|
65878a |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
65878a |
Date: Fri, 11 Oct 2013 19:33:20 -0400
|
|
|
65878a |
Subject: [PATCH] dbus-common: avoid leak in error path
|
|
|
65878a |
|
|
|
65878a |
src/shared/dbus-common.c:968:33: warning: Potential leak of memory pointed to by 'l'
|
|
|
65878a |
return -EINVAL;
|
|
|
65878a |
^~~~~~
|
|
|
65878a |
---
|
|
|
65878a |
src/shared/dbus-common.c | 20 ++++++++++----------
|
|
|
65878a |
1 file changed, 10 insertions(+), 10 deletions(-)
|
|
|
65878a |
|
|
|
65878a |
diff --git a/src/shared/dbus-common.c b/src/shared/dbus-common.c
|
|
|
65878a |
index c727cae..3ba2d87 100644
|
|
|
65878a |
--- a/src/shared/dbus-common.c
|
|
|
65878a |
+++ b/src/shared/dbus-common.c
|
|
|
65878a |
@@ -934,7 +934,7 @@ int bus_parse_strv_iter(DBusMessageIter *iter, char ***_l) {
|
|
|
65878a |
int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) {
|
|
|
65878a |
DBusMessageIter sub, sub2;
|
|
|
65878a |
unsigned n = 0, i = 0;
|
|
|
65878a |
- char **l;
|
|
|
65878a |
+ _cleanup_strv_free_ char **l = NULL;
|
|
|
65878a |
|
|
|
65878a |
assert(iter);
|
|
|
65878a |
assert(_l);
|
|
|
65878a |
@@ -953,6 +953,7 @@ int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) {
|
|
|
65878a |
l = new(char*, n*2+1);
|
|
|
65878a |
if (!l)
|
|
|
65878a |
return -ENOMEM;
|
|
|
65878a |
+ l[0] = NULL; /* make sure that l is properly terminated at all times */
|
|
|
65878a |
|
|
|
65878a |
dbus_message_iter_recurse(iter, &sub);
|
|
|
65878a |
|
|
|
65878a |
@@ -968,26 +969,25 @@ int bus_parse_strv_pairs_iter(DBusMessageIter *iter, char ***_l) {
|
|
|
65878a |
return -EINVAL;
|
|
|
65878a |
|
|
|
65878a |
l[i] = strdup(a);
|
|
|
65878a |
- if (!l[i]) {
|
|
|
65878a |
- strv_free(l);
|
|
|
65878a |
+ if (!l[i])
|
|
|
65878a |
return -ENOMEM;
|
|
|
65878a |
- }
|
|
|
65878a |
+ i++;
|
|
|
65878a |
|
|
|
65878a |
- l[++i] = strdup(b);
|
|
|
65878a |
- if (!l[i]) {
|
|
|
65878a |
- strv_free(l);
|
|
|
65878a |
+ l[i] = strdup(b);
|
|
|
65878a |
+ if (!l[i])
|
|
|
65878a |
return -ENOMEM;
|
|
|
65878a |
- }
|
|
|
65878a |
-
|
|
|
65878a |
i++;
|
|
|
65878a |
+
|
|
|
65878a |
dbus_message_iter_next(&sub);
|
|
|
65878a |
}
|
|
|
65878a |
|
|
|
65878a |
assert(i == n*2);
|
|
|
65878a |
l[i] = NULL;
|
|
|
65878a |
|
|
|
65878a |
- if (_l)
|
|
|
65878a |
+ if (_l) {
|
|
|
65878a |
*_l = l;
|
|
|
65878a |
+ l = NULL; /* avoid freeing */
|
|
|
65878a |
+ }
|
|
|
65878a |
|
|
|
65878a |
return 0;
|
|
|
65878a |
}
|