linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Zhu Yanhai <yanhai.zhu@linux.intel.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] Don't pass down NULL path to dbus if no modem.
Date: Wed, 13 Jan 2010 08:28:20 +0200	[thread overview]
Message-ID: <20100113062819.GA16896@jh-x301> (raw)
In-Reply-To: <1263276935-7456-1-git-send-email-yanhai.zhu@linux.intel.com>

Hi,

On Tue, Jan 12, 2010, Zhu Yanhai wrote:
> --- a/audio/telephony-ofono.c
> +++ b/audio/telephony-ofono.c
> @@ -574,12 +574,20 @@ static void list_modem_reply(DBusPendingCall *call, void *user_data)
>  	while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
>  
>  		dbus_message_iter_get_basic(&sub, &modem_obj_path_local);
> +		if (modem_obj_path_local == NULL)
> +			continue;

dbus_message_iter_get_basic doesn't set the pointer to NULL in the case
of failure, so this check is useless. The D-Bus documentation says the
following about dbus_message_iter_get_basic:

"Be sure you have somehow checked that dbus_message_iter_get_arg_type()
matches the type you are expecting, or you'll crash when you try to use
an integer as a string or something."

You could either change the while loop condition from
"!= DBUS_TYPE_INVALID" to "== DBUS_TYPE_STRING", or if you just want to
pick the first modem in the list (which probably makes more sense than
the current method of picking the last one and leaking the path to every
modem before it) remove the loop completely and then bail out (goto
done) if the first parameter isn't a string.

In the future, please check the reference documentation instead of
guessing the usage of the API. You can find it e.g. here:
http://dbus.freedesktop.org/doc/api/html/group__DBus.html

>  		modem_obj_path = g_strdup(modem_obj_path_local);
> -		debug("modem_obj_path is %p, %s\n", modem_obj_path,
> +		debug("modem_obj_path is %p, %s", modem_obj_path,
>  						modem_obj_path);

The removal of the unnecessary newline character is good, but there are
a few other issues that are strange with this:

1. What's the value of printing the memory address of the string here?
2. Leaking modem_obj_path if it was already set

Since there are a few different issues to fix here, feel free to split
them up into separate patches (e.g. the summary of the commit message
isn't accurate anymore).

Johan

  parent reply	other threads:[~2010-01-13  6:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-12  6:15 [PATCH] Don't pass down NULL path to dbus if no modem Zhu Yanhai
2010-01-12  6:25 ` Zhu Yanhai
2010-01-13  6:28 ` Johan Hedberg [this message]
2010-01-13  6:52   ` Zhu Yanhai
2010-01-13  7:35     ` Johan Hedberg
2010-01-13  7:46       ` Zhu Yanhai
  -- strict thread matches above, loose matches on Subject: below --
2010-01-11  7:36 Zhu Yanhai
2010-01-11 13:53 ` Johan Hedberg

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=20100113062819.GA16896@jh-x301 \
    --to=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=yanhai.zhu@linux.intel.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;
as well as URLs for NNTP newsgroup(s).