diff options
author | Philipp Tölke <toelke@in.tum.de> | 2010-07-30 23:35:17 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2010-07-30 23:35:17 +0000 |
commit | e08568a24c162baab3366399cb9e6c31b8568f09 (patch) | |
tree | 0af570fd8ab7f4dabe8aae8865eed4f9dc794184 /src | |
parent | 0e1f9223b2b2524d855983aee0d207e7d07aaaf4 (diff) | |
download | gnunet-e08568a24c162baab3366399cb9e6c31b8568f09.tar.gz gnunet-e08568a24c162baab3366399cb9e6c31b8568f09.zip |
Streamline the memory-allocation
Diffstat (limited to 'src')
-rw-r--r-- | src/vpn/gnunet-daemon-vpn.c | 4 | ||||
-rw-r--r-- | 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) | |||
174 | GNUNET_GETOPT_OPTION_END | 174 | GNUNET_GETOPT_OPTION_END |
175 | }; | 175 | }; |
176 | 176 | ||
177 | struct vpn_cls* cls = (struct vpn_cls*)malloc(sizeof(struct vpn_cls)); | 177 | struct vpn_cls* cls = GNUNET_malloc(sizeof(struct vpn_cls)); |
178 | 178 | ||
179 | return (GNUNET_OK == | 179 | return (GNUNET_OK == |
180 | GNUNET_PROGRAM_run (argc, | 180 | GNUNET_PROGRAM_run (argc, |
@@ -183,7 +183,7 @@ main (int argc, char *const *argv) | |||
183 | gettext_noop ("help text"), | 183 | gettext_noop ("help text"), |
184 | options, &run, cls)) ? ret : 1; | 184 | options, &run, cls)) ? ret : 1; |
185 | 185 | ||
186 | free(cls); // Make clang happy | 186 | GNUNET_free(cls); // Make clang happy |
187 | } | 187 | } |
188 | 188 | ||
189 | /* end of gnunet-daemon-vpn.c */ | 189 | /* 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) {{{ | |||
109 | }}} | 109 | }}} |
110 | 110 | ||
111 | void pkt_printf(struct ip6_pkt* pkt) {{{ | 111 | void pkt_printf(struct ip6_pkt* pkt) {{{ |
112 | char* buf = (char*)malloc(strlen(pretty)+1); | 112 | char* buf = alloca(strlen(pretty)+1); |
113 | char tmp[9]; | 113 | char tmp[9]; |
114 | 114 | ||
115 | memcpy(buf, pretty, strlen(pretty)+1); | 115 | memcpy(buf, pretty, strlen(pretty)+1); |
@@ -146,7 +146,6 @@ void pkt_printf(struct ip6_pkt* pkt) {{{ | |||
146 | } | 146 | } |
147 | 147 | ||
148 | printf("%s", buf); | 148 | printf("%s", buf); |
149 | free(buf); | ||
150 | }}} | 149 | }}} |
151 | 150 | ||
152 | void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{ | 151 | void pkt_printf_ip6tcp(struct ip6_tcp* pkt) {{{ |
@@ -267,13 +266,13 @@ void pkt_printf_ip6dns(struct ip6_udp_dns* pkt) {{{ | |||
267 | printf("\t#ns: %d\n", ntohs(pkt->data.nscount)); | 266 | printf("\t#ns: %d\n", ntohs(pkt->data.nscount)); |
268 | printf("\t#ar: %d\n", ntohs(pkt->data.arcount)); | 267 | printf("\t#ar: %d\n", ntohs(pkt->data.arcount)); |
269 | 268 | ||
270 | struct dns_query** queries = (struct dns_query**)malloc(qdcount*sizeof(struct dns_query*)); | 269 | struct dns_query** queries = alloca(qdcount*sizeof(struct dns_query*)); |
271 | unsigned int idx = 0; | 270 | unsigned int idx = 0; |
272 | 271 | ||
273 | int i; | 272 | int i; |
274 | for (i = 0; i < qdcount; i++) { | 273 | for (i = 0; i < qdcount; i++) { |
275 | queries[i] = (struct dns_query*)malloc(sizeof(struct dns_query)); | 274 | queries[i] = alloca(sizeof(struct dns_query)); |
276 | queries[i]->name = (unsigned char*)malloc(255); // see RFC1035 | 275 | queries[i]->name = alloca(255); // see RFC1035 |
277 | unsigned char* name = queries[i]->name; | 276 | unsigned char* name = queries[i]->name; |
278 | int len = pkt->data.data[idx++]; | 277 | int len = pkt->data.data[idx++]; |
279 | while (len != 0) { | 278 | while (len != 0) { |