From e4d663a531205cdb281318bc912d76f2be22b328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Thu, 11 Jul 2013 18:47:22 +0300 Subject: [PATCH 1/2] Fix ztree_txn_* API to work ztree_clone() sets ztclone->zones to valid pointer even where it was NULL in the original ztree. This happens since malloc(0) returns always valid pointer. This confuses _ztree_update() and various other places as in several cases ->zones is tested instead of ->zones_len. Fix ztree_clone() to keep ->zones as NULL if the original had it as NULL. --- gdnsd/ztree.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gdnsd/ztree.c b/gdnsd/ztree.c index 57ff6d6..3924504 100644 --- a/gdnsd/ztree.c +++ b/gdnsd/ztree.c @@ -526,9 +526,14 @@ static ztree_t* ztree_clone(const ztree_t* original) { ztree_t* ztclone = malloc(sizeof(ztree_t)); ztclone->label = original->label; - ztclone->zones = malloc(original->zones_len * sizeof(zone_t*)); - memcpy(ztclone->zones, original->zones, original->zones_len * sizeof(zone_t*)); - ztclone->zones_len = original->zones_len; + if (original->zones) { + ztclone->zones = malloc(original->zones_len * sizeof(zone_t*)); + memcpy(ztclone->zones, original->zones, original->zones_len * sizeof(zone_t*)); + ztclone->zones_len = original->zones_len; + } else { + ztclone->zones = NULL; + ztclone->zones_len = 0; + } ztchildren_t* old_ztc = original->children; if(old_ztc) { ztchildren_t* new_ztc = ztclone->children = calloc(1, sizeof(ztchildren_t)); -- 1.8.3.2