From: Michael Stapelberg Date: Wed, 31 Aug 2011 12:44:48 +0000 (+0200) Subject: properly free memory/close fd upon errors (Thanks xeen) X-Git-Tag: 4.1~171^2^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=e1631d6320cf6b47c3b46f0b56ae970986c9c20c;p=i3%2Fi3 properly free memory/close fd upon errors (Thanks xeen) Found with the static analyzer cppcheck --- diff --git a/src/cfgparse.y b/src/cfgparse.y index c0bf92af..5b2b4b5c 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -188,6 +188,7 @@ static char *migrate_config(char *input, off_t size) { ret = read(readpipe[0], converted + read_bytes, conv_size - read_bytes); if (ret == -1) { warn("Cannot read from pipe"); + FREE(converted); return NULL; } read_bytes += ret; diff --git a/src/ipc.c b/src/ipc.c index dfb1fd68..5f4d59cc 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -59,8 +59,10 @@ static bool mkdirp(const char *path) { copy[strlen(copy)-1] = '\0'; char *sep = strrchr(copy, '/'); - if (sep == NULL) + if (sep == NULL) { + FREE(copy); return false; + } *sep = '\0'; bool result = false; if (mkdirp(copy)) diff --git a/src/util.c b/src/util.c index fc0a5ceb..2d6c3e14 100644 --- a/src/util.c +++ b/src/util.c @@ -374,11 +374,13 @@ char *store_restart_layout() { if (n == -1) { perror("write()"); free(filename); + close(fd); return NULL; } if (n == 0) { printf("write == 0?\n"); free(filename); + close(fd); return NULL; } written += n;