Streamline the memory-allocation
authorPhilipp Tölke <toelke@in.tum.de>
Fri, 30 Jul 2010 23:35:17 +0000 (23:35 +0000)
committerPhilipp Tölke <toelke@in.tum.de>
Fri, 30 Jul 2010 23:35:17 +0000 (23:35 +0000)
src/vpn/gnunet-daemon-vpn.c
src/vpn/gnunet-vpn-pretty-print.c

index ddd540cb0744874f409ff00b6c6c340252665dca..0f5b3b06ef64d4fbfb6695b4b8f522024bd1bc1e 100644 (file)
@@ -174,7 +174,7 @@ main (int argc, char *const *argv)
     GNUNET_GETOPT_OPTION_END
   };
 
-  struct vpn_cls* cls = (struct vpn_cls*)malloc(sizeof(struct vpn_cls));
+  struct vpn_cls* cls = GNUNET_malloc(sizeof(struct vpn_cls));
 
   return (GNUNET_OK ==
           GNUNET_PROGRAM_run (argc,
@@ -183,7 +183,7 @@ main (int argc, char *const *argv)
                               gettext_noop ("help text"),
                               options, &run, cls)) ? ret : 1;
 
-  free(cls); // Make clang happy
+  GNUNET_free(cls); // Make clang happy
 }
 
 /* end of gnunet-daemon-vpn.c */
index d7edf0a119ad1e794b753464e8d6d35828fa082e..81678d37574dd9e3fc7684e6c79282821c810a85 100644 (file)
@@ -109,7 +109,7 @@ void pp_write_header(char* dest, struct ip6_pkt* pkt) {{{
 }}}
 
 void pkt_printf(struct ip6_pkt* pkt) {{{
-       char* buf = (char*)malloc(strlen(pretty)+1);
+       char* buf = alloca(strlen(pretty)+1);
        char tmp[9];
 
        memcpy(buf, pretty, strlen(pretty)+1);
@@ -146,7 +146,6 @@ void pkt_printf(struct ip6_pkt* pkt) {{{
        }
 
        printf("%s", buf);
-       free(buf);
 }}}
 
 void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{
@@ -267,13 +266,13 @@ void pkt_printf_ip6dns(struct ip6_udp_dns* pkt) {{{
        printf("\t#ns: %d\n", ntohs(pkt->data.nscount));
        printf("\t#ar: %d\n", ntohs(pkt->data.arcount));
        
-       struct dns_query** queries = (struct dns_query**)malloc(qdcount*sizeof(struct dns_query*));
+       struct dns_query** queries = alloca(qdcount*sizeof(struct dns_query*));
        unsigned int idx = 0;
 
        int i;
        for (i = 0; i < qdcount; i++) {
-               queries[i] = (struct dns_query*)malloc(sizeof(struct dns_query));
-               queries[i]->name = (unsigned char*)malloc(255); // see RFC1035
+               queries[i] = alloca(sizeof(struct dns_query));
+               queries[i]->name = alloca(255); // see RFC1035
                unsigned char* name = queries[i]->name;
                int len = pkt->data.data[idx++];
                while (len != 0) {