From: Ildar Kamaletdinov Date: Sat, 7 May 2022 17:35:03 +0000 (+0300) Subject: tools: Fix memory leaks in btgatt-server/client X-Git-Tag: accepted/tizen/unified/20230608.164325~255 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=54fa6c51f987dba465eabdf59e9322521f14ac85;p=platform%2Fupstream%2Fbluez.git tools: Fix memory leaks in btgatt-server/client According to man buffer allocated by getline() should be freed by the user program even if getline() failed. Found by Linux Verification Center (linuxtesting.org) with the SVACE static analysis tool. Signed-off-by: Manika Shrivastava Signed-off-by: Ayush Garg --- diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c index 69d6419..b936a6a 100755 --- a/tools/btgatt-client.c +++ b/tools/btgatt-client.c @@ -1369,12 +1369,16 @@ static void prompt_read_cb(int fd, uint32_t events, void *user_data) return; } - if ((read = getline(&line, &len, stdin)) == -1) + read = getline(&line, &len, stdin); + if (read < 0) { + free(line); return; + } if (read <= 1) { cmd_help(cli, NULL); print_prompt(); + free(line); return; } diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c index 6c36d47..03230b2 100755 --- a/tools/btgatt-server.c +++ b/tools/btgatt-server.c @@ -1079,12 +1079,15 @@ static void prompt_read_cb(int fd, uint32_t events, void *user_data) } read = getline(&line, &len, stdin); - if (read < 0) + if (read < 0) { + free(line); return; + } if (read <= 1) { cmd_help(server, NULL); print_prompt(); + free(line); return; }