From ad4b2f37e0f51a90c160edbe8633589ce42e60b9 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 3 Jul 2003 01:50:25 +0000 Subject: [PATCH] 1479. [bug] cfg_create_tuple() failed to handle out of memory cleanup. parse_list() would leak memory on syntax errors. --- CHANGES | 4 ++++ lib/isccfg/parser.c | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index b48773d455..7c0c114e9a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +1479. [bug] cfg_create_tuple() failed to handle out of + memory cleanup. parse_list() would leak memory + on syntax errors. + 1478. [port] ifconfig.sh didn't account for other virtual interfaces. It now takes a optional arguement to specify the first interface number. [RT #3907] diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index 2c4e435573..903c684d7a 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: parser.c,v 1.109 2003/07/03 00:43:28 marka Exp $ */ +/* $Id: parser.c,v 1.110 2003/07/03 01:50:25 marka Exp $ */ #include @@ -216,7 +216,8 @@ cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) { return (ISC_R_SUCCESS); cleanup: - CLEANUP_OBJ(obj); + if (obj != NULL) + isc_mem_put(pctx->mctx, obj, sizeof(*obj)); return (result); } @@ -973,24 +974,26 @@ parse_list(cfg_parser_t *pctx, const cfg_type_t *listtype, cfg_obj_t **ret) cfg_obj_t *listobj = NULL; const cfg_type_t *listof = listtype->of; isc_result_t result; + cfg_listelt_t *elt = NULL; CHECK(cfg_create_list(pctx, listtype, &listobj)); for (;;) { - cfg_listelt_t *elt = NULL; - CHECK(cfg_peektoken(pctx, 0)); if (pctx->token.type == isc_tokentype_special && - pctx->token.value.as_char == '}') + pctx->token.value.as_char == /*{*/ '}') break; CHECK(cfg_parse_listelt(pctx, listof, &elt)); CHECK(parse_semicolon(pctx)); ISC_LIST_APPEND(listobj->value.list, elt, link); + elt = NULL; } *ret = listobj; return (ISC_R_SUCCESS); cleanup: + if (elt != NULL) + free_list_elt(pctx, elt); CLEANUP_OBJ(listobj); return (result); } @@ -1303,7 +1306,6 @@ parse_symtab_elt(cfg_parser_t *pctx, const char *name, CHECK(isc_symtab_define(symtab, name, 1, symval, isc_symexists_reject)); - obj = NULL; return (ISC_R_SUCCESS); cleanup: