[lxc-devel] [PATCH 1/1] cppcheck: fix unchecked realloc in lxc_info.c

Serge Hallyn serge.hallyn at ubuntu.com
Tue Apr 15 20:53:35 UTC 2014


Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
---
 src/lxc/lxc_info.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/lxc/lxc_info.c b/src/lxc/lxc_info.c
index 24d6f9b..e1e39c0 100644
--- a/src/lxc/lxc_info.c
+++ b/src/lxc/lxc_info.c
@@ -50,9 +50,13 @@ static int filter_count = 0;
 
 static int my_parser(struct lxc_arguments* args, int c, char* arg)
 {
+	char **newk;
 	switch (c) {
 	case 'c':
-		key = realloc(key, keys+1 * sizeof(key[0]));
+		newk = realloc(key, keys+1 * sizeof(key[0]));
+		if (!newk)
+			return -1;
+		key = newk;
 		key[keys] = arg;
 		keys++;
 		break;
-- 
1.9.1



More information about the lxc-devel mailing list