mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-26 23:53:28 +01:00
fix potential memory leak and move cleanup to the end of the function
This commit is contained in:
parent
833b724e9f
commit
79bde4e5bf
@ -130,11 +130,12 @@ static int save_blocklist(char *path)
|
|||||||
exit_toxic_err("Failed in save_blocklist", FATALERR_MEMORY);
|
exit_toxic_err("Failed in save_blocklist", FATALERR_MEMORY);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
int ret = -1;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for (i = 0; i < Blocked.max_idx; ++i) {
|
for (i = 0; i < Blocked.max_idx; ++i) {
|
||||||
if (count > Blocked.num_blocked)
|
if (count > Blocked.num_blocked)
|
||||||
return -1;
|
goto on_error;
|
||||||
|
|
||||||
if (Blocked.list[i].active) {
|
if (Blocked.list[i].active) {
|
||||||
BlockedFriend tmp;
|
BlockedFriend tmp;
|
||||||
@ -155,17 +156,14 @@ static int save_blocklist(char *path)
|
|||||||
|
|
||||||
FILE *fp = fopen(path, "wb");
|
FILE *fp = fopen(path, "wb");
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL)
|
||||||
free(data);
|
goto on_error;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ret = 0;
|
if (fwrite(data, len, 1, fp) == 1)
|
||||||
|
ret = 0;
|
||||||
if (fwrite(data, len, 1, fp) != 1)
|
|
||||||
ret = -1;
|
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
on_error:
|
||||||
free(data);
|
free(data);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user