1
0
mirror of https://github.com/Tha14/toxic.git synced 2025-07-04 23:46:44 +02:00

more thorough error checking

This commit is contained in:
Jfreegman
2014-09-23 22:51:56 -04:00
parent 48cf4ebf02
commit b071a9e992
11 changed files with 93 additions and 23 deletions

View File

@ -163,6 +163,7 @@ static int save_blocklist(char *path)
ret = 0;
fclose(fp);
on_error:
free(data);
return ret;
@ -180,9 +181,22 @@ int load_blocklist(char *path)
if (fp == NULL)
return -1;
fseek(fp, 0, SEEK_END);
if (fseek(fp, 0L, SEEK_END) == -1) {
fclose(fp);
return -1;
}
int len = ftell(fp);
fseek(fp, 0, SEEK_SET);
if (len == -1) {
fclose(fp);
return -1;
}
if (fseek(fp, 0L, SEEK_SET) == -1) {
fclose(fp);
return -1;
}
char *data = malloc(len);