From d8e8abdff9203ca0809ad40011f8e277edf16d5f Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 17 Jan 2013 14:38:28 +1100 Subject: [PATCH] Silence "Access to field 'refs' results in a dereference of a null pointer" by adding appropriate assertions. --- lib/isccfg/include/isccfg/cfg.h | 4 ++++ lib/isccfg/parser.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/isccfg/include/isccfg/cfg.h b/lib/isccfg/include/isccfg/cfg.h index f467768344..9997c0697f 100644 --- a/lib/isccfg/include/isccfg/cfg.h +++ b/lib/isccfg/include/isccfg/cfg.h @@ -411,6 +411,10 @@ cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **obj); /*%< * Delete a reference to a configuration object; destroy the object if * there are no more references. + * + * Require: + * \li '*obj' is a valid cfg_obj_t. + * \li 'pctx' is a valid cfg_parser_t. */ void diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index ef20184f39..b56b0d59b6 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -2426,9 +2426,14 @@ cfg_obj_istype(const cfg_obj_t *obj, const cfg_type_t *type) { */ void cfg_obj_destroy(cfg_parser_t *pctx, cfg_obj_t **objp) { - cfg_obj_t *obj = *objp; + cfg_obj_t *obj; unsigned int refs; + REQUIRE(objp != NULL && *objp != NULL); + REQUIRE(pctx != NULL); + + obj = *objp; + isc_refcount_decrement(&obj->references, &refs); if (refs == 0) { obj->type->rep->free(pctx, obj);