From 8151a57f9141febb0a183e8f1ade6417e0a8ec97 Mon Sep 17 00:00:00 2001 From: Willem Toorop Date: Fri, 23 Sep 2011 11:49:21 +0000 Subject: [PATCH] Code review from Wouter. Fix potential memory leak --- host2str.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/host2str.c b/host2str.c index 5679fe07..eff1216a 100644 --- a/host2str.c +++ b/host2str.c @@ -1167,13 +1167,15 @@ ldns_b32_ext2dname(const ldns_rdf *rdf) size = ldns_b32_ntop_calculate_size(ldns_rdf_size(rdf) - 1); /* add one for the end nul for the string */ b32 = LDNS_XMALLOC(char, size + 2); - if (b32 && ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1, + if (b32) { + if (ldns_b32_ntop_extended_hex(ldns_rdf_data(rdf) + 1, ldns_rdf_size(rdf) - 1, b32, size+1) > 0) { - b32[size] = '.'; - b32[size+1] = '\0'; - if (ldns_str2rdf_dname(&out, b32) == LDNS_STATUS_OK) { - LDNS_FREE(b32); - return out; + b32[size] = '.'; + b32[size+1] = '\0'; + if (ldns_str2rdf_dname(&out, b32) == LDNS_STATUS_OK) { + LDNS_FREE(b32); + return out; + } } LDNS_FREE(b32); } -- 2.47.3