summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorNick White <git@njw.me.uk>2012-07-11 14:25:24 +0100
committerNick White <git@njw.me.uk>2012-07-11 14:25:24 +0100
commit57e231682732c1e3c1ce36cd0298760a853dfd64 (patch)
tree70031f965111dadf8e645dcab1de93af6a8c0087 /util.c
parent4f3b1d683997bf0e3c6ecf997dee5796eb78b4fc (diff)
Be more careful about freeing memory
Diffstat (limited to 'util.c')
-rw-r--r--util.c11
1 files 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);
}