diff options
author | Nick White <git@njw.me.uk> | 2012-07-11 14:25:24 +0100 |
---|---|---|
committer | Nick White <git@njw.me.uk> | 2012-07-11 14:25:24 +0100 |
commit | 57e231682732c1e3c1ce36cd0298760a853dfd64 (patch) | |
tree | 70031f965111dadf8e645dcab1de93af6a8c0087 | |
parent | 4f3b1d683997bf0e3c6ecf997dee5796eb78b4fc (diff) |
Be more careful about freeing memory
-rw-r--r-- | util.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -99,6 +99,8 @@ int request(char *host, char *request, char *savecookie, char **body) { } } + free(buf); + return l; } @@ -163,14 +165,19 @@ int renameifjpg(char *path) { return 1; if(fgetc(f) == 255) { - if((newpath = malloc(strlen(path) + 1)) == NULL) + if((newpath = malloc(strlen(path) + 1)) == NULL) { + fclose(f); return 1; + } strncpy(newpath, path, strlen(path)); c = strrchr(newpath, '.'); strncpy(c+1, "jpg\0", 4); - if(rename(path, newpath)) + if(rename(path, newpath)) { + free(newpath); + fclose(f); return 1; + } free(newpath); } |