All of lore.kernel.org
 help / color / mirror / Atom feed
From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
To: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	naota <naota@elisp.net>
Subject: Re: [PATCH 1/2] Fix wrong memory free on check_is_root
Date: Thu, 18 Dec 2014 16:16:06 +0900	[thread overview]
Message-ID: <54927F36.6010701@jp.fujitsu.com> (raw)
In-Reply-To: <1418886214.5832.6.camel@localhost.localdomain>

On 2014/12/18 16:03, Gui Hecheng wrote:
> On Thu, 2014-12-18 at 15:09 +0900, Satoru Takeuchi wrote:
>> From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
>> Date: Thu, 18 Dec 2014 14:35:22 +0900
>>
>> @tmp is freed even if its allocation fails.
>>
>> Signed-off-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
>>
>> ---
>>   cmds-property.c | 13 +++++++------
>>   1 file changed, 7 insertions(+), 6 deletions(-)
>>
>> diff --git a/cmds-property.c b/cmds-property.c
>> index a764293..a4bc127 100644
>> --- a/cmds-property.c
>> +++ b/cmds-property.c
>> @@ -140,31 +140,32 @@ static int check_is_root(const char *object)
>
> Hi Satoru,
> 	" tmp = malloc()
> 	  if (!tmp) {
> 		...
> 		goto out;
> 	  }
> 	"
> Actually, if the malloc() fails, it returns a NULL, and the free()
> handles the NULL internally.
> I think there is no special need to deal with this case by the prog
> itself.

Oh, sorry... my brain would be broken today.

Thanks,
Satoru

>
> Thanks,
> Gui
>
>>   	if (ret < 0) {
>>   		fprintf(stderr, "ERROR: get_fsid for %s failed. %s\n", object,
>>   				strerror(-ret));
>> -		goto out;
>> +		goto free_tmp_out;
>>   	}
>>
>>   	ret = get_fsid(tmp, fsid2, 1);
>>   	if (ret == -ENOTTY) {
>>   		ret = 0;
>> -		goto out;
>> +		goto free_tmp_out;
>>   	} else if (ret == -ENOTDIR) {
>>   		ret = 1;
>> -		goto out;
>> +		goto free_tmp_out;
>>   	} else if (ret < 0) {
>>   		fprintf(stderr, "ERROR: get_fsid for %s failed. %s\n", tmp,
>>   			strerror(-ret));
>> -		goto out;
>> +		goto free_tmp_out;
>>   	}
>>
>>   	if (memcmp(fsid, fsid2, BTRFS_FSID_SIZE)) {
>>   		ret = 0;
>> -		goto out;
>> +		goto free_tmp_out;
>>   	}
>>
>>   	ret = 1;
>>
>> -out:
>> +free_tmp_out:
>>   	free(tmp);
>> +out:
>>   	return ret;
>>   }
>>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


      reply	other threads:[~2014-12-18  7:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-18  6:09 [PATCH 1/2] Fix wrong memory free on check_is_root Satoru Takeuchi
2014-12-18  6:42 ` [PATCH 2/2] btrfs-progs: fix the file system root is regarded as non-root Satoru Takeuchi
2014-12-18  7:09   ` Gui Hecheng
2014-12-18  7:19     ` Satoru Takeuchi
2014-12-18  7:03 ` [PATCH 1/2] Fix wrong memory free on check_is_root Gui Hecheng
2014-12-18  7:16   ` Satoru Takeuchi [this message]

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=54927F36.6010701@jp.fujitsu.com \
    --to=takeuchi_satoru@jp.fujitsu.com \
    --cc=guihc.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=naota@elisp.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.