From 57e231682732c1e3c1ce36cd0298760a853dfd64 Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 11 Jul 2012 14:25:24 +0100 Subject: Be more careful about freeing memory --- util.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 4130188..b263f9f 100644 --- a/util.c +++ b/util.c @@ -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); } -- cgit v1.2.3