From e08568a24c162baab3366399cb9e6c31b8568f09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Philipp=20T=C3=B6lke?= Date: Fri, 30 Jul 2010 23:35:17 +0000 Subject: [PATCH] Streamline the memory-allocation --- src/vpn/gnunet-daemon-vpn.c | 4 ++-- src/vpn/gnunet-vpn-pretty-print.c | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/vpn/gnunet-daemon-vpn.c b/src/vpn/gnunet-daemon-vpn.c index ddd540cb0..0f5b3b06e 100644 --- a/src/vpn/gnunet-daemon-vpn.c +++ b/src/vpn/gnunet-daemon-vpn.c @@ -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 */ diff --git a/src/vpn/gnunet-vpn-pretty-print.c b/src/vpn/gnunet-vpn-pretty-print.c index d7edf0a11..81678d375 100644 --- a/src/vpn/gnunet-vpn-pretty-print.c +++ b/src/vpn/gnunet-vpn-pretty-print.c @@ -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) { -- 2.25.1