From: Wouter Wijngaards Date: Wed, 10 Mar 2010 11:01:33 +0000 (+0000) Subject: alloc_lite works X-Git-Tag: release-1.4.3~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46df44f321643c38dfa8b783ca8e39e76ba789b2;p=thirdparty%2Funbound.git alloc_lite works git-svn-id: file:///svn/unbound/trunk@2015 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index 64c6fb682..3d32cb218 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,3 +1,6 @@ +10 March 2010: Wouter + - --enable-alloc-lite works with test set. + 9 March 2010: Wouter - tag 1.4.2 created. - trunk is 1.4.3 in development. diff --git a/libunbound/libworker.c b/libunbound/libworker.c index 315a791b3..dc54b03a2 100644 --- a/libunbound/libworker.c +++ b/libunbound/libworker.c @@ -484,8 +484,15 @@ setup_qinfo_edns(struct libworker* w, struct ctx_query* q, if(!rdf) { return 0; } +#ifdef UNBOUND_ALLOC_LITE + qinfo->qname = memdup(ldns_rdf_data(rdf), ldns_rdf_size(rdf)); + qinfo->qname_len = ldns_rdf_size(rdf); + ldns_rdf_deep_free(rdf); + rdf = 0; +#else qinfo->qname = ldns_rdf_data(rdf); qinfo->qname_len = ldns_rdf_size(rdf); +#endif edns->edns_present = 1; edns->ext_rcode = 0; edns->edns_version = 0; diff --git a/smallapp/unbound-host.c b/smallapp/unbound-host.c index 5f32b7b71..5b76f5143 100644 --- a/smallapp/unbound-host.c +++ b/smallapp/unbound-host.c @@ -48,6 +48,14 @@ #undef free #undef realloc #endif +#ifdef UNBOUND_ALLOC_LITE +#undef malloc +#undef calloc +#undef free +#undef realloc +#undef strdup +char* unbound_lite_wrapstr(char* s) { return s; } +#endif #include "libunbound/unbound.h" #include diff --git a/testcode/asynclook.c b/testcode/asynclook.c index c203f75a2..9ee4312da 100644 --- a/testcode/asynclook.c +++ b/testcode/asynclook.c @@ -45,6 +45,13 @@ #include "libunbound/context.h" #include "util/locks.h" #include "util/log.h" +#ifdef UNBOUND_ALLOC_LITE +#undef malloc +#undef calloc +#undef realloc +#undef free +#undef strdup +#endif /** keeping track of the async ids */ struct track_id { diff --git a/testcode/harvest.c b/testcode/harvest.c index f0b6f90c4..4f27dda6f 100644 --- a/testcode/harvest.c +++ b/testcode/harvest.c @@ -74,6 +74,14 @@ #ifdef HAVE_SYS_STAT_H #include #endif +#ifdef UNBOUND_ALLOC_LITE +#undef malloc +#undef calloc +#undef realloc +#undef free +#undef strdup +char* unbound_lite_wrapstr(char* s) { return s; } +#endif struct todo_item; struct labdata; diff --git a/util/alloc.c b/util/alloc.c index d530aa4ff..be8d5b9f5 100644 --- a/util/alloc.c +++ b/util/alloc.c @@ -589,4 +589,50 @@ char* unbound_strdup_lite(const char* s, const char* file, int line, memmove(n, s, l); return n; } + +char* unbound_lite_wrapstr(char* s) +{ + char* n = unbound_strdup_lite(s, __FILE__, __LINE__, __func__); + free(s); + return n; +} + +#undef ldns_pkt2wire +ldns_status unbound_lite_pkt2wire(uint8_t **dest, const ldns_pkt *p, + size_t *size) +{ + uint8_t* md = NULL; + size_t ms = 0; + ldns_status s = ldns_pkt2wire(&md, p, &ms); + if(md) { + *dest = unbound_stat_malloc_lite(ms, __FILE__, __LINE__, + __func__); + *size = ms; + if(!*dest) { free(md); return LDNS_STATUS_MEM_ERR; } + memcpy(*dest, md, ms); + free(md); + } else { + *dest = NULL; + *size = 0; + } + return s; +} + +#undef i2d_DSA_SIG +int unbound_lite_i2d_DSA_SIG(DSA_SIG* dsasig, unsigned char** sig) +{ + unsigned char* n = NULL; + int r= i2d_DSA_SIG(dsasig, &n); + if(n) { + *sig = unbound_stat_malloc_lite((size_t)r, __FILE__, __LINE__, + __func__); + if(!*sig) return -1; + memcpy(*sig, n, (size_t)r); + free(n); + return r; + } + *sig = NULL; + return r; +} + #endif /* UNBOUND_ALLOC_LITE */ diff --git a/util/alloc.h b/util/alloc.h index e0810afaa..50da0c2ed 100644 --- a/util/alloc.h +++ b/util/alloc.h @@ -195,6 +195,18 @@ void *unbound_stat_realloc_lite(void *ptr, size_t size, const char* file, # define strdup(s) unbound_strdup_lite(s, __FILE__, __LINE__, __func__) char* unbound_strdup_lite(const char* s, const char* file, int line, const char* func); +char* unbound_lite_wrapstr(char* s); +# define ldns_rr2str(rr) unbound_lite_wrapstr(ldns_rr2str(rr)) +# define ldns_rdf2str(rdf) unbound_lite_wrapstr(ldns_rdf2str(rdf)) +# define ldns_rr_type2str(t) unbound_lite_wrapstr(ldns_rr_type2str(t)) +# define ldns_rr_class2str(c) unbound_lite_wrapstr(ldns_rr_class2str(c)) +# define ldns_rr_list2str(r) unbound_lite_wrapstr(ldns_rr_list2str(r)) +# define ldns_pkt2str(p) unbound_lite_wrapstr(ldns_pkt2str(p)) +# define ldns_pkt_rcode2str(r) unbound_lite_wrapstr(ldns_pkt_rcode2str(r)) +# define ldns_pkt2wire(a, r, s) unbound_lite_pkt2wire(a, r, s) +ldns_status unbound_lite_pkt2wire(uint8_t **dest, const ldns_pkt *p, size_t *size); +# define i2d_DSA_SIG(d, s) unbound_lite_i2d_DSA_SIG(d, s) +int unbound_lite_i2d_DSA_SIG(DSA_SIG* dsasig, unsigned char** sig); #endif /* UNBOUND_ALLOC_LITE */ #endif /* UTIL_ALLOC_H */