From af351a21f24be576687e060d17a2951466b7be21 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 30 Dec 2009 06:40:36 +0100 Subject: [PATCH] [ipaccess] Start using talloc in the firmware code * We are not leaking anything... *yeah*, talloc rocks --- openbsc/src/Makefile.am | 2 +- openbsc/src/ipaccess/ipaccess-firmware.c | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am index e665c99eb..2d9df992c 100644 --- a/openbsc/src/Makefile.am +++ b/openbsc/src/Makefile.am @@ -39,6 +39,6 @@ isdnsync_SOURCES = isdnsync.c bsc_mgcp_SOURCES = bsc_mgcp.c msgb.c talloc.c debug.c select.c timer.c telnet_interface.c bsc_mgcp_LDADD = libvty.a -ipaccess_firmware_SOURCES = ipaccess/ipaccess-firmware.c +ipaccess_firmware_SOURCES = ipaccess/ipaccess-firmware.c talloc.c ipaccess_proxy_SOURCES = ipaccess/ipaccess-proxy.c msgb.c select.c talloc.c debug.c timer.c diff --git a/openbsc/src/ipaccess/ipaccess-firmware.c b/openbsc/src/ipaccess/ipaccess-firmware.c index 431fe315c..36a42df58 100644 --- a/openbsc/src/ipaccess/ipaccess-firmware.c +++ b/openbsc/src/ipaccess/ipaccess-firmware.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -39,6 +40,9 @@ static_assert(sizeof(struct sdp_firmware) == 160, _right_header_length); /* more magic, the second "int" in the header */ static char more_magic[] = { 0x10, 0x02 }; +/* talloc context */ +void *tall_firm_ctx; + int ipacces_analyze_file(int fd, const unsigned int st_size, const unsigned int base_offset, struct llist_head *list) { struct sdp_firmware *firmware_header = 0; @@ -75,7 +79,7 @@ int ipacces_analyze_file(int fd, const unsigned int st_size, const unsigned int } /* add the firmware */ - header = malloc(sizeof(*header)); + header = talloc_zero(list, struct sdp_header); header->firmware_info = *firmware_header; INIT_LLIST_HEAD(&header->header_list); llist_add(&header->entry, list); @@ -114,7 +118,7 @@ int ipacces_analyze_file(int fd, const unsigned int st_size, const unsigned int return -1; } - header_entry = malloc(sizeof(*header_entry)); + header_entry = talloc_zero(header, struct sdp_header_item); header_entry->header_entry = entry; llist_add(&header_entry->entry, &header->header_list); @@ -132,8 +136,10 @@ int main(int argc, char** argv) for (i = 1; i < argc; ++i) { struct sdp_header *header; struct sdp_header_item *sub_entry; - struct llist_head entry; - INIT_LLIST_HEAD(&entry); + struct llist_head *entry; + + entry = talloc_zero(tall_firm_ctx, struct llist_head); + INIT_LLIST_HEAD(entry); printf("Opening possible firmware '%s'\n", argv[i]); fd = open(argv[i], O_RDONLY); @@ -148,9 +154,9 @@ int main(int argc, char** argv) return EXIT_FAILURE; } - ipacces_analyze_file(fd, stat.st_size, 0, &entry); + ipacces_analyze_file(fd, stat.st_size, 0, entry); - llist_for_each_entry(header, &entry, entry) { + llist_for_each_entry(header, entry, entry) { printf("Printing header information:\n"); printf("more_more_magic: 0x%x\n", ntohs(header->firmware_info.more_more_magic)); printf("header_length: %u\n", ntohl(header->firmware_info.header_length)); @@ -177,8 +183,9 @@ int main(int argc, char** argv) printf("\n\n"); } printf("\n\n"); - } + + talloc_free(entry); }