alloc_lite works

git-svn-id: file:///svn/unbound/trunk@2015 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2010-03-10 11:01:33 +00:00
parent 0000843c32
commit 46df44f321
7 changed files with 91 additions and 0 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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 <ldns/ldns.h>

View File

@ -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 {

View File

@ -74,6 +74,14 @@
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#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;

View File

@ -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 */

View File

@ -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 */