dns: use bss instead of heap for buffers
authorFelix Fietkau <nbd@openwrt.org>
Tue, 3 Jun 2014 21:03:41 +0000 (23:03 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 3 Jun 2014 21:03:41 +0000 (23:03 +0200)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
dns.c
dns.h
main.c

diff --git a/dns.c b/dns.c
index 75e739dbfa63d88ecf7a0f5f47059831f0331317..6389f8cc15e4ae64d5a5aae557fc2535001bc283 100644 (file)
--- a/dns.c
+++ b/dns.c
@@ -36,8 +36,8 @@
 #include "util.h"
 #include "dns.h"
 
-char *rdata_buffer;
-static char *name_buffer;
+char rdata_buffer[MAX_DATA_LEN + 1];
+static char name_buffer[MAX_NAME_LEN + 1];
 
 const char*
 dns_type_string(uint16_t type)
@@ -330,25 +330,3 @@ dns_consume_name(uint8_t *base, int blen, uint8_t **data, int *len)
 
        return name_buffer;
 }
-
-int
-dns_init(void)
-{
-       name_buffer = malloc(MAX_NAME_LEN + 1);
-       rdata_buffer = malloc(MAX_DATA_LEN + 1);
-
-       if (!name_buffer || !rdata_buffer)
-               return -1;
-
-       memset(name_buffer, 0, MAX_NAME_LEN + 1);
-       memset(rdata_buffer, 0, MAX_NAME_LEN + 1);
-
-       return 0;
-}
-
-void
-dns_cleanup(void)
-{
-       free(name_buffer);
-       free(rdata_buffer);
-}
diff --git a/dns.h b/dns.h
index b29e297f37996566f9f7333fe1db581b04ffed5c..45901231847984724a1262ab931107bd2fe4ad4c 100644 (file)
--- a/dns.h
+++ b/dns.h
@@ -64,10 +64,8 @@ struct dns_question {
        uint16_t class;
 } __attribute__((packed, aligned(2)));
 
-extern char *rdata_buffer;
+extern char rdata_buffer[MAX_DATA_LEN + 1];
 
-extern int dns_init(void);
-extern void dns_cleanup(void);
 extern void dns_send_question(struct uloop_fd *u, char *question, int type);
 extern void dns_init_answer(void);
 extern void dns_add_answer(int type, uint8_t *rdata, uint16_t rdlength);
diff --git a/main.c b/main.c
index cc179038521173a38081b5a79313b7e5468930a3..39b83207fa7d406e72a07ec26fb44dad916d9788 100644 (file)
--- a/main.c
+++ b/main.c
@@ -237,9 +237,6 @@ main(int argc, char **argv)
        fprintf(stderr, "interface %s has ip %s and index %d\n", iface_name, iface_ip, iface_index);
        signal_setup();
 
-       if (dns_init())
-               return -1;
-
        if (cache_init())
                return -1;
 
@@ -254,7 +251,6 @@ main(int argc, char **argv)
        uloop_run();
        uloop_done();
 
-       dns_cleanup();
        cache_cleanup();
        service_cleanup();