[augeas-devel] [PATCH] check for a few failed memory allocations

Jim Meyering jim at meyering.net
Mon Apr 28 17:55:58 UTC 2008


There are may more, but you have to start somewhere...

* src/augtool.c: check for a few failed memory allocations

diff --git a/src/augtool.c b/src/augtool.c
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -370,11 +370,14 @@
     if (state == 0) {
         char *end = strrchr(text, SEP);
         char *path;
-        if (end == NULL)
-            path = strdup("/*");
-        else {
+        if (end == NULL) {
+            if ((path = strdup("/*")) == NULL)
+                return NULL;
+        } else {
             end += 1;
             CALLOC(path, end - text + 2);
+            if (path == NULL)
+                return NULL;
             strncpy(path, text, end - text);
             strcat(path, "*");
         }
@@ -392,7 +395,10 @@
         current += 1;
         if (STREQLEN(child, text, strlen(text))) {
             if (child_count(child) > 0) {
-                child = realloc(child, strlen(child)+2);
+                char *c = realloc(child, strlen(child)+2);
+                if (c == NULL)
+                    return NULL;
+                child = c;
                 strcat(child, "/");
             }
             rl_filename_completion_desired = 1;




More information about the augeas-devel mailing list