From 5fca7ef4838c6a8aede8a5e338940804e8e363f7 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Mon, 28 Oct 2019 15:44:42 +0100 Subject: [HICN-363] Fix memory leaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7617becdb520f20caca341be11fbb8c1054de021 Signed-off-by: Jordan Augé --- hicn-light/src/hicn/socket/api.c | 45 +++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'hicn-light/src/hicn/socket/api.c') diff --git a/hicn-light/src/hicn/socket/api.c b/hicn-light/src/hicn/socket/api.c index a3d5a3cfe..34c0aae54 100644 --- a/hicn-light/src/hicn/socket/api.c +++ b/hicn-light/src/hicn/socket/api.c @@ -72,7 +72,8 @@ hicn_socket_helper_t *hicn_create() { } hicn->conf = malloc(sizeof(hicn_conf_t)); - if (hicn->conf < 0) goto ERR_CONF; + if (hicn->conf < 0) + goto ERR_CONF; memcpy(hicn->conf, &hicn_default_conf, sizeof(hicn_conf_t)); /* Initialize socket tree to empty */ @@ -126,64 +127,56 @@ ERR_MALLOC: void hicn_destroy() { int rc; + int ret = 0; uint16_t i; /* Restore default rules */ printf("Restoring default configuration.\n"); rc = ops.del_lo_prio_rule(NULL, AF_INET6, LOCAL_PRIORITY); - if (rc < 0) { - goto ERR; - } + if (rc < 0) + ret = -1; rc = ops.del_lo_prio_rule(NULL, AF_INET, LOCAL_PRIORITY); - if (rc < 0) { - goto ERR; - } + if (rc < 0) + ret = -1; rc = ops.add_lo_prio_rule(NULL, AF_INET6, 0); - if (rc < 0) { - goto ERR; - } + if (rc < 0) + ret = -1; rc = ops.add_lo_prio_rule(NULL, AF_INET, 0); - if (rc < 0) { - goto ERR; - } + if (rc < 0) + ret = -1; for (i = 0; i < rules_counter; i++) { if (strcmp(rules_to_remove[i].tun_name, "NONE") != 0) { rc = ops.del_rule(rules_to_remove[i].tun_name, rules_to_remove[i].address_family, rules_to_remove[i].table_id); - if (rc < 0) { - goto ERR; - } } else { rc = ops.del_prio_rule( &rules_to_remove[i].prefix, rules_to_remove[i].address_family, rules_to_remove[i].priority, rules_to_remove[i].table_id); - if (rc < 0) { - goto ERR; - } } + if (rc < 0) + ret = -1; } for (i = 0; i < routes_counter; i++) { rc = ops.del_out_route(routes_to_remove[i].remote_ip_address, routes_to_remove[i].address_family, routes_to_remove[i].table_id); - if (rc < 0) { - goto ERR; - } + if (rc < 0) + ret = -1; } -ERR: - if (rc < 0) printf("Unexpected exit. Some state may not be deleted.\n"); - return; + if (ret < 0) + printf("Unexpected exit. Some state may not be deleted.\n"); } void hicn_free(hicn_socket_helper_t *hicn) { - // close tun ? + hicn_destroy(); + free(hicn->conf); free(hicn); } -- cgit 1.2.3-korg