return NULL from psl_load_file() if the file could not be read.

This commit is contained in:
Daniel Kahn Gillmor 2014-03-21 14:43:27 -04:00
parent 4e674ccbae
commit c07ea9d0a0
1 changed files with 9 additions and 7 deletions

View File

@ -275,12 +275,12 @@ psl_ctx_t *psl_load_file(const char *fname)
if (!(psl = calloc(1, sizeof(psl_ctx_t))))
return NULL;
if ((fp = fopen(fname, "r"))) {
// as of 02.11.2012, the list at http://publicsuffix.org/list/ contains ~6000 rules and 40 exceptions.
// as of 19.02.2014, the list at http://publicsuffix.org/list/ contains ~6500 rules and 19 exceptions.
psl->suffixes = _vector_alloc(8*1024, _suffix_compare);
psl->suffix_exceptions = _vector_alloc(64, _suffix_compare);
if ((fp = fopen(fname, "r"))) {
while ((linep = fgets(buf, sizeof(buf), fp))) {
while (isspace(*linep)) linep++; // ignore leading whitespace
if (!*linep) continue; // skip empty lines
@ -312,8 +312,10 @@ psl_ctx_t *psl_load_file(const char *fname)
_vector_sort(psl->suffix_exceptions);
_vector_sort(psl->suffixes);
} else
fprintf(stderr, _("Failed to open PSL file '%s'\n"), fname);
} else {
free(psl);
return NULL;
}
return psl;
}