From: Mark Andrews Date: Thu, 13 Dec 2012 00:18:01 +0000 (+1100) Subject: 3440. [bug] Reorder get_key_struct to not trigger a assertion when X-Git-Tag: v9.10.0a1~659 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=fcc04c160feef526cc209ca03e8bbdfe34afd83b;p=thirdparty%2Fbind9.git 3440. [bug] Reorder get_key_struct to not trigger a assertion when cleaning up due to out of memory error. [RT #32131] --- diff --git a/CHANGES b/CHANGES index a7bdc99883a..d2bcc6e83e4 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +3440. [bug] Reorder get_key_struct to not trigger a assertion when + cleaning up due to out of memory error. [RT #32131] + 3439. [placeholder] 3438. [bug] Don't accept unknown data escape in quotes. [RT #32031] diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index 6ab5df13b85..217259b2f67 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -1326,24 +1326,24 @@ get_key_struct(dns_name_t *name, unsigned int alg, return (NULL); memset(key, 0, sizeof(dst_key_t)); - key->magic = KEY_MAGIC; - - result = isc_refcount_init(&key->refs, 1); - if (result != ISC_R_SUCCESS) { - isc_mem_put(mctx, key, sizeof(dst_key_t)); - return (NULL); - } key->key_name = isc_mem_get(mctx, sizeof(dns_name_t)); if (key->key_name == NULL) { - isc_refcount_destroy(&key->refs); isc_mem_put(mctx, key, sizeof(dst_key_t)); return (NULL); } + dns_name_init(key->key_name, NULL); result = dns_name_dup(name, mctx, key->key_name); if (result != ISC_R_SUCCESS) { - isc_refcount_destroy(&key->refs); + isc_mem_put(mctx, key->key_name, sizeof(dns_name_t)); + isc_mem_put(mctx, key, sizeof(dst_key_t)); + return (NULL); + } + + result = isc_refcount_init(&key->refs, 1); + if (result != ISC_R_SUCCESS) { + dns_name_free(key->key_name, mctx); isc_mem_put(mctx, key->key_name, sizeof(dns_name_t)); isc_mem_put(mctx, key, sizeof(dst_key_t)); return (NULL); @@ -1363,6 +1363,7 @@ get_key_struct(dns_name_t *name, unsigned int alg, key->times[i] = 0; key->timeset[i] = ISC_FALSE; } + key->magic = KEY_MAGIC; return (key); }