cli: fix realloc issue spotted by cppcheck
[project/uci.git] / cli.c
diff --git a/cli.c b/cli.c
index f8b45db..1ce4d5e 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -113,8 +113,16 @@ uci_lookup_section_ref(struct uci_section *s)
                maxlen = strlen(s->type) + 1 + 2 + 10;
                if (!typestr) {
                        typestr = malloc(maxlen);
+                       if (!typestr)
+                               return NULL;
                } else {
-                       typestr = realloc(typestr, maxlen);
+                       void *p = realloc(typestr, maxlen);
+                       if (!p) {
+                               free(typestr);
+                               return NULL;
+                       }
+
+                       typestr = p;
                }
 
                if (typestr)