Release unused memory after loading DAFSA data
This commit is contained in:
parent
f829668e0d
commit
96e0848d81
|
@ -1127,6 +1127,7 @@ psl_ctx_t *psl_load_fp(FILE *fp)
|
||||||
buf[n] = 0;
|
buf[n] = 0;
|
||||||
|
|
||||||
if (!strstr(buf, "This Source Code Form is subject to")) {
|
if (!strstr(buf, "This Source Code Form is subject to")) {
|
||||||
|
void *m;
|
||||||
size_t size = 65536, len = n;
|
size_t size = 65536, len = n;
|
||||||
|
|
||||||
if (!(psl->dafsa = malloc(size)))
|
if (!(psl->dafsa = malloc(size)))
|
||||||
|
@ -1137,13 +1138,16 @@ psl_ctx_t *psl_load_fp(FILE *fp)
|
||||||
while ((n = fread(psl->dafsa + len, 1, size - len, fp)) > 0) {
|
while ((n = fread(psl->dafsa + len, 1, size - len, fp)) > 0) {
|
||||||
len += n;
|
len += n;
|
||||||
if (len >= size) {
|
if (len >= size) {
|
||||||
void *m = realloc(psl->dafsa, size *= 2);
|
if (!(m = realloc(psl->dafsa, size *= 2)))
|
||||||
if (!m)
|
|
||||||
goto fail;
|
goto fail;
|
||||||
psl->dafsa = m;
|
psl->dafsa = m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* release unused memory */
|
||||||
|
if ((m = realloc(psl->dafsa, len)))
|
||||||
|
psl->dafsa = m;
|
||||||
|
|
||||||
return psl;
|
return psl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue