X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fmdnsd.git;a=blobdiff_plain;f=cache.c;h=07a08575aa3639c819eb605f760017a6180b571b;hp=da65b1f4b4d327b2eaa8608a460864b01ddf40ce;hb=28bf0f6d036eaa7ef3cf628f0663ba65b26db040;hpb=d76c21865eed783deb18a34a4f497f3da50320c9 diff --git a/cache.c b/cache.c index da65b1f..07a0857 100644 --- a/cache.c +++ b/cache.c @@ -66,10 +66,6 @@ cache_entry_free(struct cache_entry *s) { DBG(2, "%s\n", s->entry); avl_delete(&entries, &s->avl); - if (s->host) - free(s->host); - if (s->entry) - free(s->entry); free(s); } @@ -162,21 +158,26 @@ static struct cache_entry* cache_entry(struct uloop_fd *u, char *entry, int hlen, int ttl) { struct cache_entry *s; + char *entry_buf; + char *host_buf; char *type; s = avl_find_element(&entries, entry, s, avl); if (s) return s; - s = malloc(sizeof(struct cache_entry)); - memset(s, 0, sizeof(struct cache_entry)); - s->avl.key = s->entry = strdup(entry); + s = calloc_a(sizeof(*s), + &entry_buf, strlen(entry) + 1, + &host_buf, hlen ? hlen + 1 : 0); + + s->avl.key = s->entry = strcpy(entry_buf, entry); s->time = time(NULL); s->ttl = ttl; if (hlen) - s->host = strndup(s->entry, hlen); - type = strstr(s->entry, "._"); + s->host = strncpy(host_buf, s->entry, hlen); + + type = strstr(entry_buf, "._"); if (type) type++; if (type)