From: Tobias Klauser Date: Tue, 17 Jun 2008 22:47:33 +0000 (+0200) Subject: collect: check realloc return value X-Git-Tag: 174~1680 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=322fc7a636296ba9a3f93912661f14c65c2af4b2;p=systemd collect: check realloc return value --- diff --git a/extras/collect/collect.c b/extras/collect/collect.c index feb0e757..9fb6737d 100644 --- a/extras/collect/collect.c +++ b/extras/collect/collect.c @@ -53,7 +53,7 @@ static LIST_HEAD(bunch); static int debug; /* This can increase dynamically */ -static int bufsize = BUFSIZE; +static size_t bufsize = BUFSIZE; static void sig_alrm(int signo) { @@ -272,8 +272,15 @@ static int missing(int fd) ret++; } else { while (strlen(him->name)+1 >= bufsize) { + char *tmpbuf; + bufsize = bufsize << 1; - buf = realloc(buf, bufsize); + tmpbuf = realloc(buf, bufsize); + if (!tmpbuf) { + free(buf); + return -1; + } + buf = tmpbuf; } snprintf(buf, strlen(him->name)+2, "%s ", him->name); write(fd, buf, strlen(buf));