Skip to content

Commit

Permalink
Fix memory leaks in ec_network.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Koeppe committed Jan 7, 2023
1 parent d9ad7bd commit 71dbb15
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/ec_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,15 @@ void network_init()

static void close_network()
{
pcap_close(EC_GBL_IFACE->pcap);
SAFE_FREE(EC_GBL_IFACE->pbuf);
source_close(EC_GBL_IFACE);

if(EC_GBL_SNIFF->type == SM_BRIDGED) {
pcap_close(EC_GBL_BRIDGE->pcap);
SAFE_FREE(EC_GBL_BRIDGE->pbuf);
source_close(EC_GBL_BRIDGE);
}

if(EC_GBL_OPTIONS->write)
pcap_dump_close(EC_GBL_PCAP->dump);

libnet_destroy(EC_GBL_IFACE->lnet);
libnet_destroy(EC_GBL_BRIDGE->lnet);

DEBUG_MSG("ATEXIT: close_network");
}

Expand Down Expand Up @@ -325,8 +321,9 @@ static int source_init(char *name, struct iface_env *source, bool primary, bool

static void source_close(struct iface_env *iface)
{
DEBUG_MSG("source_close(%s)", iface->name);
#ifdef WITH_IPV6
struct net_list *n;
struct net_list *n, *tmp;
#endif

iface->is_ready = 0;
Expand All @@ -338,13 +335,16 @@ static void source_close(struct iface_env *iface)
libnet_destroy(iface->lnet);

#ifdef WITH_IPV6
LIST_FOREACH(n, &iface->ip6_list, next) {
LIST_REMOVE(n, next);
SAFE_FREE(n);
if (iface->has_ipv6) {
LIST_FOREACH_SAFE(n, &iface->ip6_list, next, tmp) {
LIST_REMOVE(n, next);
SAFE_FREE(n);
}
}
#endif

SAFE_FREE(iface->name);
SAFE_FREE(iface->pbuf);
memset(iface, 0, sizeof(*iface));
}

Expand Down

0 comments on commit 71dbb15

Please sign in to comment.