Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4679951iob; Sun, 8 May 2022 21:45:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzIqTwRWmLgx9Fv+HBsA2jCBPUOoRjp4Al1BG3OLtutu9sAz5bKK9aN975VtYxvPCj6XIcn X-Received: by 2002:a63:9553:0:b0:3c6:25b2:9525 with SMTP id t19-20020a639553000000b003c625b29525mr11877300pgn.294.1652071519306; Sun, 08 May 2022 21:45:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652071519; cv=none; d=google.com; s=arc-20160816; b=nOp8RG480JX70PrtsA5IujBbw+kcSsNXkspwxSbSf8ngnUQSna9Uf3Z+xGT501XMBi s4LgB6yVanVzC6z7lGGJSlvmQ45ElLUMT3VERL86JEe2A2MTWfOBGajf97mm0LehAqPY nTv3aza69ZqLoUGt1CaoU891HCksmvo1LV26FvozIcXlt237+1ZZUtpNVZL9HklH15nx eOn+o08wYiFLs9skDwIQZ2wdn8IBZMRATSMMywDeEMG3/YP+lP2T6thzFZc32pmh0X5M 0tFPaZ2Sy0wPCA+DpBwdBbtOVbdFXCMjwFpiQ9I9KylZyGWVEjie7qbM9Q9Vr6X6c6wi CmGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-filter; bh=V5g5BTdGq8eNGXTxtYZj3FGm6u8rZTExkgpmsVI0rKc=; b=eLSIHu/mdZphZGylGMnZ2Mx4JWLRNW4ZhabfWBFJEjARm2u69RXAK881oMTMkf+z1H 83qW3nsAGlSTZARgR5GcbgV2cv7/yqJs+jkwBAShI/ZShOKVe76p9SEWvC0q6YNI5H5P tP0hAqGXgCsn/Gi1RfLEbgmlth8McI6W/eFOpyGJwWpQ/cPyu1TWv6oQDVzd3zMJRTVz ZDTkdMZOYyZP24evE2kGmt0ZXGSYqU5NU6FBaOradE0y4fFczcNWTgG6J+WUwn9nQ8ev Fmv8NoszMpv9p0rkzNzyfBtatZ4Lh2/acF8xSbaWxHXsLHswdSya2wRasQE4I6IjGoXQ ogTg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id pc10-20020a17090b3b8a00b001d2a6056609si18000069pjb.47.2022.05.08.21.45.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 21:45:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-bluetooth-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 229F6A774B; Sun, 8 May 2022 21:45:09 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238956AbiEGPQt (ORCPT + 99 others); Sat, 7 May 2022 11:16:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354601AbiEGPQr (ORCPT ); Sat, 7 May 2022 11:16:47 -0400 Received: from mxout01.lancloud.ru (mxout01.lancloud.ru [45.84.86.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773F12D1FD for ; Sat, 7 May 2022 08:12:58 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout01.lancloud.ru C539920D0FA5 Received: from LanCloud Received: from LanCloud Received: from LanCloud From: Ildar Kamaletdinov To: CC: Ildar Kamaletdinov Subject: [PATCH BlueZ 2/4] tools: Fix memory leaks in btgatt-server/client Date: Sat, 7 May 2022 18:06:55 +0300 Message-ID: <20220507150657.28240-3-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220507150657.28240-1-i.kamaletdinov@omp.ru> References: <20220507150657.28240-1-i.kamaletdinov@omp.ru> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [192.168.11.198] X-ClientProxiedBy: LFEXT01.lancloud.ru (fd00:f066::141) To LFEX1910.lancloud.ru (fd00:f066::80) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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. --- tools/btgatt-client.c | 5 ++++- tools/btgatt-server.c | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c index 8c9365aa2..9447062fb 100644 --- a/tools/btgatt-client.c +++ b/tools/btgatt-client.c @@ -1355,12 +1355,15 @@ static void prompt_read_cb(int fd, uint32_t events, void *user_data) return; } - if ((read = getline(&line, &len, stdin)) == -1) + if ((read = getline(&line, &len, stdin)) == -1) { + 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 4a5d2b720..90a6c9b0a 100644 --- a/tools/btgatt-server.c +++ b/tools/btgatt-server.c @@ -1080,12 +1080,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; } -- 2.35.3