1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-07-01 16:37:46 +02:00

fix potential memory leak and move cleanup to the end of the function

This commit is contained in:
Andriy Voskoboinyk 2014-09-04 19:49:50 +03:00
parent 833b724e9f
commit 79bde4e5bf

View File

@ -130,11 +130,12 @@ static int save_blocklist(char *path)
exit_toxic_err("Failed in save_blocklist", FATALERR_MEMORY);
int i;
int ret = -1;
int count = 0;
for (i = 0; i < Blocked.max_idx; ++i) {
if (count > Blocked.num_blocked)
return -1;
goto on_error;
if (Blocked.list[i].active) {
BlockedFriend tmp;
@ -155,17 +156,14 @@ static int save_blocklist(char *path)
FILE *fp = fopen(path, "wb");
if (fp == NULL) {
free(data);
return -1;
}
if (fp == NULL)
goto on_error;
int ret = 0;
if (fwrite(data, len, 1, fp) != 1)
ret = -1;
if (fwrite(data, len, 1, fp) == 1)
ret = 0;
fclose(fp);
on_error:
free(data);
return ret;
}