Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp765435pxj; Tue, 18 May 2021 13:41:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkPaOS4vJ0aF3pOkjuhRk9dqC9HmMXOd/tGb22cNIRkimGUBiKa6ES3v5r/udrVs4BtMj9 X-Received: by 2002:a50:fb0f:: with SMTP id d15mr9259588edq.343.1621370498373; Tue, 18 May 2021 13:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621370498; cv=none; d=google.com; s=arc-20160816; b=Hf4Hn065MSSCrFtnXtKxv90jxG7lifpwk4WiukhpDqctWR3pU7YJx6YbzZ48qFCbyS ShFj78jmxlLNNYKeRLTkV0qkPGhbvRv9YogRQ2I9HioZC0/Z/LiHjOw/z6tfiO0cvVed F8kval/0sjoml+erxngAY2bDVA1xIiCNQBNepSyqI5bf6cppv3wJDEkeFxwveoKujT2/ 6WjT8UtwKg1/neEb4ZySTTDDG6k7N+Mz5OdHh9P+4XymqBXntakGuCzD+o0tb+V0mZKJ 5lH+JzwwMqE9aCD+6l3gFRBXodmrZxkFuqREqozMSqP/oEkufIDJ7xlfa8O7n2AXk4Y2 g3Mw== 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 :user-agent:references:in-reply-to:date:to:from:subject:message-id :dkim-signature; bh=czs6JRqNIf7QdQUc60mBgkL4AfLpnyGt/i/VHJNAXfU=; b=u5rbQUH1nivsqYgC2ixExnY2FC9YvvO8UjtysIurbOHTDj9zGf4pnopg+94v/cVMA/ 0heh+BP03RHvxde6PvchshXzF7haQFE7oC8osa0Q97VAvCQ2MfrCFHev5zzIIKz2vnrg vy8zs6TNtV+RRWjEeloW+pkM3HScefgfj3bRzzwdnaXFyVJhlrGbhJdVXcFDEWgQQjH+ 1q4nZXvoI1TbVgqWxLuJSsAs0LQaCm41HVu+EPT5ux+lYzsWTUCzSo7q5DLcUGuJN0Rt e1iQ/cKbxe7GxqtrDiF1bI2eAqgs9vy+YtcPRD8vcJAtzVCG7oPlTxeuHb/YW3F2Jfko qo4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="YT/VK6dI"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y20si14409995ejr.527.2021.05.18.13.41.02; Tue, 18 May 2021 13:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="YT/VK6dI"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236991AbhEQRMS (ORCPT + 99 others); Mon, 17 May 2021 13:12:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235732AbhEQRMR (ORCPT ); Mon, 17 May 2021 13:12:17 -0400 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 722BAC061573 for ; Mon, 17 May 2021 10:11:00 -0700 (PDT) Received: by mail-pj1-x1035.google.com with SMTP id o17-20020a17090a9f91b029015cef5b3c50so5938296pjp.4 for ; Mon, 17 May 2021 10:11:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=czs6JRqNIf7QdQUc60mBgkL4AfLpnyGt/i/VHJNAXfU=; b=YT/VK6dI/gyxTNVpUVuyTW4WDc2fe2jdrab3LKg2ZyPMtf9c1p98WCH/hw6deOpImM WEDnMAUAlMR9KROAKP1VrYYndg/ZEzXl7VmtmzC4vkNF31jkJSBRgtmj+1Ju9w6jpiPt /jSzA4U4ztW7lA4KecIVUuOFSRXRVJ8TUJcYQgTn2vGZ9dBsIPk3A2AdCRPVD9Id3LUj SZ/TJN4Fh5nSXhoiqvjI4UYl910rptMIX6ZTFmnvqjkkg4LQ3SbzKM3UsYmOhGNLb0t/ kRadzGYbsP8HQmhSjgiF+N3sBe+3O6Dk0+U1O/B7qeDLktYmSqd5IgTGvr/J348PU/KT G3MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=czs6JRqNIf7QdQUc60mBgkL4AfLpnyGt/i/VHJNAXfU=; b=hrCovc6Eh3UZXA7OUlyWy6ocshwWF4APAGo7FZLwMNLuQ+hNcFomf9ZX7qg8ocLmyg JCVr1E64k4UO+giN39DfxcVdzo5xK2JkQEJDiMg1RTA7aojCtT7nneFyRBnLKa9+xciE wHfSUtB9Pqn8fDPTD5Gfla0UJhPDmU9Pv4x9A5fdwLDW6f6WQySujk2yfGbvJYEG/pkS nY9IlC2885wdlkgyxiOuJet1/VE5RznsM/H6XNDDm2dyqusxn0Rb73uhiSRWOQZqhrpI aBPVA4VdCjDQMlt9hh2c1DODr8kgrVB/09XItaaqVdMQ9C7Klx3A/jcVX1a+DhOxhdn5 xI5g== X-Gm-Message-State: AOAM531FPnm0rxFTv3Wu8QgAReB2oK5OT2NJUX1zG05D3eNgO2LpV/W4 IUQe/K9tncTFmohwnHHE2NX68+feknBtgA== X-Received: by 2002:a17:90a:c42:: with SMTP id u2mr515958pje.10.1621271459997; Mon, 17 May 2021 10:10:59 -0700 (PDT) Received: from han1-mobl3 ([2601:1c0:6a01:d830::f604]) by smtp.gmail.com with ESMTPSA id u1sm10872957pgh.80.2021.05.17.10.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 10:10:59 -0700 (PDT) Message-ID: <9af2be8769f9b8b1146424a72735084984fde825.camel@gmail.com> Subject: Re: [Bluez PATCH ] Fix memory leaks in obex From: Tedd Ho-Jeong An To: Steve Grubb , linux-bluetooth@vger.kernel.org Date: Mon, 17 May 2021 10:10:58 -0700 In-Reply-To: <20210515094307.16fb1572@ivy-bridge> References: <20210515094307.16fb1572@ivy-bridge> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Steve, On Sat, 2021-05-15 at 09:43 -0400, Steve Grubb wrote: > This patch fixes a couple memory leaks. > > In filesystem, g_file_get_contents allocates fresh memory to buf. > It needs to be freed after conversion to a GString object. > > Destination was missed on an error path as is mld. > > --- > obexd/plugins/filesystem.c | 2 +- > obexd/plugins/ftp.c | 8 ++++++-- > obexd/plugins/messages-dummy.c | 1 + > 3 files changed, 8 insertions(+), 3 deletions(-) > > diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c > index 09bff8ad0..44e3cf3d2 100644 > --- a/obexd/plugins/filesystem.c > +++ b/obexd/plugins/filesystem.c@@ -416,6 +416,7 @@ static void *capability_open(const char *name, int oflag, mode_t mode, CI wasn't able to apply the patch and couldn't run the tests, and I think because of this line. > } > > object->buffer = g_string_new(buf); > + g_free(buf); > > if (size) > *size = object->buffer->len; > diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c > index 259bfcae2..4b04bab06 100644 > --- a/obexd/plugins/ftp.c > +++ b/obexd/plugins/ftp.c > @@ -386,8 +386,10 @@ static int ftp_copy(struct ftp_session *ftp, const char *name, > ret = verify_path(destdir); > g_free(destdir); > > - if (ret < 0) > + if (ret < 0) { > + g_free(destination); > return ret; > + } > > source = g_build_filename(ftp->folder, name, NULL); > > @@ -424,8 +426,10 @@ static int ftp_move(struct ftp_session *ftp, const char *name, > ret = verify_path(destdir); > g_free(destdir); > > - if (ret < 0) > + if (ret < 0) { > + g_free(destination); > return ret; > + } > > source = g_build_filename(ftp->folder, name, NULL); > > diff --git a/obexd/plugins/messages-dummy.c b/obexd/plugins/messages-dummy.c > index 34199fa05..e37b52df6 100644 > --- a/obexd/plugins/messages-dummy.c > +++ b/obexd/plugins/messages-dummy.c > @@ -488,6 +488,7 @@ int messages_get_messages_listing(void *session, const char *name, > int err = -errno; > DBG("fopen(): %d, %s", -err, strerror(-err)); > g_free(path); > + g_free(mld); > return -EBADR; > } > }