Commit: 73bf2291378804a941c0c87af2635c54999b97a1
Parent: a36f3e3f69b7190865afa0501a91f043058ed615
Author: Randy Palamar
Date: Fri, 24 Jun 2022 17:57:14 -0600
don't leak memory when returning after an error in parse_term_bank()
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/jdict.c b/jdict.c
@@ -106,9 +106,9 @@ parse_term_bank(DictEnt *ents, size_t *nents, const char *tbank, size_t *stride)
break;
case YOMI_ERROR_INVAL: /* FALLTHROUGH */
case YOMI_ERROR_MALFO:
- munmap(data, flen);
- free(toks);
- return NULL;
+ free(ents);
+ ents = NULL;
+ goto cleanup;
}
}
@@ -116,11 +116,16 @@ parse_term_bank(DictEnt *ents, size_t *nents, const char *tbank, size_t *stride)
for (i = 0; i < r; i++) {
if (toks[i].type == YOMI_ENTRY) {
e = make_ent(&toks[i], r - i, data);
- if (e == NULL)
- return NULL;
+ if (e == NULL) {
+ free(ents);
+ ents = NULL;
+ goto cleanup;
+ }
memcpy(&ents[(*nents)++], e, sizeof(DictEnt));
}
}
+
+cleanup:
munmap(data, flen);
free(toks);