Linux bluetooth development
 help / color / mirror / Atom feed
From: Jinwang Li <jinwang.li@oss.qualcomm.com>
To: linux-bluetooth@vger.kernel.org
Cc: cheng.jiang@oss.qualcomm.com, quic_chezhou@quicinc.com,
	wei.deng@oss.qualcomm.com, shuai.zhang@oss.qualcomm.com,
	mengshi.wu@oss.qualcomm.com, jinwang.li@oss.qualcomm.com,
	xiuzhuo.shang@oss.qualcomm.com
Subject: [PATCH v1] obexd: Fix FILE* leak in phonebook-dummy
Date: Wed, 30 Sep 2026 15:39:53 +0800	[thread overview]
Message-ID: <20260930073953.266930-1-jinwang.li@oss.qualcomm.com> (raw)

fdopen(fd, "r") transfers ownership of fd to the FILE stream, but the
loop was calling close(fd) directly instead of fclose(fp), leaking the
FILE structure and its stdio buffer on every vCard read. Also handle
fdopen() failure, which was previously unchecked.

Signed-off-by: Jinwang Li <jinwang.li@oss.qualcomm.com>
---
 obexd/plugins/phonebook-dummy.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/obexd/plugins/phonebook-dummy.c b/obexd/plugins/phonebook-dummy.c
index f308ea701..43be956a5 100644
--- a/obexd/plugins/phonebook-dummy.c
+++ b/obexd/plugins/phonebook-dummy.c
@@ -164,6 +164,13 @@ static int foreach_vcard(DIR *dp, vcard_func_t func, uint16_t offset,
 		}
 
 		fp = fdopen(fd, "r");
+		if (fp == NULL) {
+			err = errno;
+			error("fdopen(%s): %s(%d)", filename, strerror(err), err);
+			close(fd);
+			continue;
+		}
+
 		v = Parse_MIME_FromFile(fp);
 		if (v != NULL) {
 			func(filename, v, user_data);
@@ -171,7 +178,7 @@ static int foreach_vcard(DIR *dp, vcard_func_t func, uint16_t offset,
 			n++;
 		}
 
-		close(fd);
+		fclose(fp);
 	}
 
 	g_slist_free_full(sorted, g_free);
-- 
2.34.1


             reply	other threads:[~2026-09-30  7:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  7:39 Jinwang Li [this message]
2026-09-30 15:08 ` [v1] obexd: Fix FILE* leak in phonebook-dummy bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260930073953.266930-1-jinwang.li@oss.qualcomm.com \
    --to=jinwang.li@oss.qualcomm.com \
    --cc=cheng.jiang@oss.qualcomm.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=mengshi.wu@oss.qualcomm.com \
    --cc=quic_chezhou@quicinc.com \
    --cc=shuai.zhang@oss.qualcomm.com \
    --cc=wei.deng@oss.qualcomm.com \
    --cc=xiuzhuo.shang@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox