From 8dc8ef598de91326cc7cd21bb705efb8b8960d1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Pavl=C3=ADn?= Date: Fri, 21 Sep 2012 12:17:23 +0200 Subject: [PATCH] udev: check malloc return in collect/collect.c Returns from no memory checks updated with log_oom call --- src/udev/collect/collect.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c index 4162c436b..47c2ddd63 100644 --- a/src/udev/collect/collect.c +++ b/src/udev/collect/collect.c @@ -142,7 +142,7 @@ static int checkout(int fd) buf = calloc(1,bufsize + 1); if (!buf) { fprintf(stderr, "Out of memory.\n"); - return -1; + return log_oom(); } memset(buf, ' ', bufsize); ptr = buf + len; @@ -167,7 +167,16 @@ static int checkout(int fd) if (debug) fprintf(stderr, "Found word %s\n", word); him = malloc(sizeof (struct _mate)); + if (!him) { + free(buf); + return log_oom(); + } him->name = strdup(word); + if (!him->name) { + free(buf); + free(him); + return log_oom(); + } him->state = STATE_OLD; udev_list_node_append(&him->node, &bunch); word = NULL; @@ -276,7 +285,7 @@ static int missing(int fd) buf = malloc(bufsize); if (!buf) - return -1; + return log_oom(); udev_list_node_foreach(him_node, &bunch) { struct _mate *him = node_to_mate(him_node); @@ -291,7 +300,7 @@ static int missing(int fd) tmpbuf = realloc(buf, bufsize); if (!tmpbuf) { free(buf); - return -1; + return log_oom(); } buf = tmpbuf; } @@ -431,7 +440,17 @@ int main(int argc, char **argv) if (debug) fprintf(stderr, "ID %s: not in database\n", argv[i]); him = malloc(sizeof (struct _mate)); + if (!him) { + ret = ENOMEM; + goto out; + } + him->name = malloc(strlen(argv[i]) + 1); + if (!him->name) { + ret = ENOMEM; + goto out; + } + strcpy(him->name, argv[i]); him->state = STATE_NONE; udev_list_node_append(&him->node, &bunch); -- 2.30.2