Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4741772iob; Sun, 8 May 2022 23:56:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzweKECZN0Ap6KR5KPcMLxBp06gxJ4kHV1SZmf1BGWbM+tGGagDn1ymwpHnlH59POZJaAP1 X-Received: by 2002:a62:cd0e:0:b0:510:8a3f:7cfa with SMTP id o14-20020a62cd0e000000b005108a3f7cfamr11651958pfg.12.1652079410778; Sun, 08 May 2022 23:56:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652079410; cv=none; d=google.com; s=arc-20160816; b=eexEsUUdSJYrkz1L53S59zwVE7QE23UKct80Me2i/7t3DWtmCL7ElEbfDB4Zyo/aGo r4/bIlk7FSrLhAZtmpdMR44W22bAiCi0Ed0dqERzRt6QHzRlDWQdJ5gLQE4+Q75i9Fxl IWQQSkiuTMfk5mfgKL7/ozslkaYqxVeSzVeSPQPyMDhvqzSBJT5ANvFLBszaGuUHxJoL iKdtAJUG/KMA5AIHKZfmEMMkqrtkhW8RJ0a6l8CLqnJ/5UWSN/3MxxpWGiqkQg+2Vfpy IpEHUnGuWRCuQRITkenDwuIIPZ8nUrIra9gRDtaM2LxTVS8H6KDgxu8AjBRGHQ1zzDKm lGHg== 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=hj4TDTKpxx14ggbXLHdhsGaLfOrEF2umBqeenV9WgeA=; b=inG3gZwpEi6Fr9eAXB1iQ2Gg3fb2B0hpXYE2V4VYu6Bdhmyc7v0OIsvckQYPANhW2Z O2gXmDzAB1SpyuzFVZsw63UHUglBwai/mVpILulVdw5+tCAhDrM7b3MIONfzm04GiUxc lmcYTqCY5O9WlFzTsL0NwGQH/GXvZHJMT0awh1V24/tohyGkhJGj+GeTngKB4eK+FbLn iR6gybLxWicWLnMH3IAYoj7ItQvQ9QD1wNwqQ9MW1S0ZxxNz7B/JGr0pclel6ibZhVMa BLnLFtwbWPjB11ShZ2KSEOmNFVyWxWAoBojMavQbRVRea2Rgoj3npXOndijqpdp9WQNi 6wlA== 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 w7-20020a1709029a8700b0015cbb6e943fsi9884968plp.299.2022.05.08.23.56.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 23:56:50 -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 3489D19876A; Sun, 8 May 2022 23:53:35 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386486AbiEGRLK (ORCPT + 99 others); Sat, 7 May 2022 13:11:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1446666AbiEGRLC (ORCPT ); Sat, 7 May 2022 13:11:02 -0400 Received: from mxout02.lancloud.ru (mxout02.lancloud.ru [45.84.86.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 694A03B555 for ; Sat, 7 May 2022 10:07:12 -0700 (PDT) Received: from LanCloud DKIM-Filter: OpenDKIM Filter v2.11.0 mxout02.lancloud.ru 331BB2225710 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 20:07:01 +0300 Message-ID: <20220507170703.29902-3-i.kamaletdinov@omp.ru> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220507170703.29902-1-i.kamaletdinov@omp.ru> References: <20220507170703.29902-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: LFEXT02.lancloud.ru (fd00:f066::142) 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 | 6 +++++- tools/btgatt-server.c | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c index 8c9365aa2..58a03bd48 100644 --- a/tools/btgatt-client.c +++ b/tools/btgatt-client.c @@ -1355,12 +1355,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 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