public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Steve Grubb <sgrubb@redhat.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] fix memory leaks
Date: Sun, 27 Sep 2009 11:31:32 +0300	[thread overview]
Message-ID: <20090927083132.GA18495@jh-x301> (raw)
In-Reply-To: <200909251623.02240.sgrubb@redhat.com>

Hi Steve,

Thanks for the excellent reviews!

There are a few changes however that I'd still do to the patch:

On Fri, Sep 25, 2009, Steve Grubb wrote:
>  	if (!record) {
>  		error("Unable to allocate new service record");
> +		g_free(server);
> +		sdp_record_free(record);
>  		return -1;
>  	}

In this branch record is NULL so I guess the sdp_record_free call is a
mistake (it also doesn't handle NULL nicely like some GLib free functions
do and would cause an imediate segfault).

> --- bluez-4.54.orig/src/glib-helper.c	2009-09-25 11:33:47.000000000 -0400
> +++ bluez-4.54/src/glib-helper.c	2009-09-25 16:07:22.000000000 -0400
> @@ -704,7 +704,7 @@ int bt_acl_encrypt(const bdaddr_t *src, 
>  			bt_hci_result_t cb, gpointer user_data)
>  {
>  	GIOChannel *io;
> -	struct hci_cmd_data *cmd;
> +	struct hci_cmd_data *cmd = NULL;
>  	struct hci_conn_info_req *cr;
>  	auth_requested_cp cp;
>  	struct hci_filter nf;
> @@ -778,6 +778,7 @@ int bt_acl_encrypt(const bdaddr_t *src, 
>  	return 0;
>  
>  failed:
> +	g_free(cmd);
>  	close(dd);

As David already mentioned in the other email, it's good to to avoid
initialization upon declaration to help the compiler detect unused
variables. I think it'd be better to add another label right above failed,
e.g. failed_cmd, which does the g_free and then jump to it from those
places in the function that need it.

Johan

  reply	other threads:[~2009-09-27  8:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-25 20:23 [PATCH] fix memory leaks Steve Grubb
2009-09-27  8:31 ` Johan Hedberg [this message]
2009-10-02  9:25 ` 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=20090927083132.GA18495@jh-x301 \
    --to=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=sgrubb@redhat.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