summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorVáclav Pavlín <vpavlin@redhat.com>2012-09-21 12:17:23 +0200
committerKay Sievers <kay@vrfy.org>2012-09-23 14:24:43 +0200
commit8dc8ef598de91326cc7cd21bb705efb8b8960d1c (patch)
tree94b41651b8f2a739a20eae1a8f778c5c28c958cd /src/udev
parentcb273c51eaf622b1e92d5ca0656b06073cb02da2 (diff)
udev: check malloc return in collect/collect.c
Returns from no memory checks updated with log_oom call
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/collect/collect.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/udev/collect/collect.c b/src/udev/collect/collect.c
index 4162c436b0..47c2ddd63e 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);