From: Guus Sliepen Date: Tue, 11 Feb 2020 20:39:36 +0000 (+0100) Subject: Fix a memory leak when an invitation file contains an invalid submesh name. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=da64ed8d36196524ec78ad4b3b350bed35f4535c;p=meshlink Fix a memory leak when an invitation file contains an invalid submesh name. Found by Clang's static analyzer. --- diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 3676e9cb..6517d9ce 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -230,17 +230,20 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat char *submesh_name = packmsg_get_str_dup(&in); if(!strcmp(submesh_name, CORE_MESH)) { + free(submesh_name); c->submesh = NULL; } else { if(!check_id(submesh_name)) { logger(mesh, MESHLINK_ERROR, "Invalid invitation file %s\n", cookie); - abort(); + free(submesh_name); return false; } c->submesh = lookup_or_create_submesh(mesh, submesh_name); + free(submesh_name); if(!c->submesh) { + logger(mesh, MESHLINK_ERROR, "Unknown submesh in invitation file %s\n", cookie); return false; } } @@ -249,7 +252,6 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat sptps_send_record(&c->sptps, 0, config.buf, config.len); config_free(&config); - free(submesh_name); c->status.invitation_used = true;