From 2d33dfd939488b81cc4a23f78f949e72391ef236 Mon Sep 17 00:00:00 2001 From: Jordan Augé Date: Wed, 20 Jan 2021 11:29:17 +0100 Subject: [HICN-668] Fix leaks + double free MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I976659b160654b511f712e65c8439b91d1cabd55 Signed-off-by: Jordan Augé --- hicn-light/src/hicn/config/configuration.c | 28 ++++++++++++++++++++-------- hicn-light/src/hicn/core/mapme.c | 3 +++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/hicn-light/src/hicn/config/configuration.c b/hicn-light/src/hicn/config/configuration.c index c4321299e..e414f05e3 100644 --- a/hicn-light/src/hicn/config/configuration.c +++ b/hicn-light/src/hicn/config/configuration.c @@ -1491,13 +1491,25 @@ void configuration_ReceiveCommand(Configuration *config, command_id command, configuration_SendResponse(config, response, ingressId); /* - * For list commands: - * - deallocate request - * - deallocate response _payload_ + * The message is originally received by a listener, and will be freed in + * different parts of the code. * - * For other commands, generating a ACK/NACK packet: - * - deallocate request - * - deallocate response, as the ACK/Nack is allocated + * For the special case of commands, a iovec is created, eg in + * udpListener::_readCommand, which has to be freed (it is commented in the + * listener). On the contrary, the original message is freed. + * + * From this function, commands are dispatched to different processing + * functions, which have two general behaviours: + * + * - LIST commands: + * . a payload for the response is allocated + * . a iovec for the response is allocated with header = request header, + * payload = newly allocated payload + * + * - Other commands: + * . a ack/nack packet is generated thanks to utils/utils.cc + * . this allocates a iovec which reuses the header of the request just + * updating the messageType field inside. */ parcMemory_Deallocate(&request); @@ -1507,11 +1519,11 @@ void configuration_ReceiveCommand(Configuration *config, command_id command, case LIST_LISTENERS: case LIST_POLICIES: /* Deallocate payload */ - parcMemory_Deallocate(&response[1] .iov_base); + parcMemory_Deallocate(&response[1].iov_base); break; default: - parcMemory_Deallocate(&response); break; } + parcMemory_Deallocate(&response); } diff --git a/hicn-light/src/hicn/core/mapme.c b/hicn-light/src/hicn/core/mapme.c index 397723a79..4ee3d5bff 100644 --- a/hicn-light/src/hicn/core/mapme.c +++ b/hicn-light/src/hicn/core/mapme.c @@ -694,6 +694,9 @@ static bool mapme_onSpecialInterest(const MapMe *mapme, FIB *fib = forwarder_getFib(mapme->forwarder); FibEntry *fibEntry = fib_Contains(fib, name); + + name_Release(&name); + if (!fibEntry) { INFO(mapme, "Ignored update with no FIB entry"); return 0; -- cgit 1.2.3-korg