All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Meyering <jim@meyering.net>
To: Pete Zaitcev <zaitcev@redhat.com>
Cc: Project Hail <hail-devel@vger.kernel.org>
Subject: Re: [PATCH hail] lib/hstor.c: avoid an unconditional leak in append_qparam
Date: Mon, 27 Sep 2010 19:05:47 +0200	[thread overview]
Message-ID: <87tylbt8us.fsf@meyering.net> (raw)
In-Reply-To: <20100927102927.45686afa@lembas.zaitcev.lan> (Pete Zaitcev's message of "Mon, 27 Sep 2010 10:29:27 -0600")

Pete Zaitcev wrote:
> On Mon, 27 Sep 2010 10:53:06 +0200
> Jim Meyering <jim@meyering.net> wrote:
>
>> -	stmp = huri_field_escape(strdup(val), QUERY_ESCAPE_MASK);
>> +	v = strdup(val);
>> +	stmp = huri_field_escape(v, QUERY_ESCAPE_MASK);
>>  	str = g_string_append(str, stmp);
>>  	free(stmp);
>> +	free(v);
>
> I think you may be fooled by the ridiculous calling convention
> of huri_field_escape(). It takes a pointer to heap, then either
> returns its argument, or reallocates it, frees the argument, and
> returns the reallocated area. It frees with g_free, so it assumes
> its equivalence with free(), haha.
>
> The end result, it either returns what strdup returned of frees it.
> Therefore if you free what strudup returned, you double-free it.

Oh!  You're right.
I missed the "g_free (signed_str);"
at the end of huri_field_escape.
Sorry about that.

> I honestly think this madness must stop and huri_field_escape
> must allocate a new buffer every time. Then we would not need
> the strdup there at all. It only exists to satisfy the requirement
> to pass a pointer to heap in case val is a const or whatnot.

Making a function like huri_field_escape free
a buffer allocated by the caller does seem to violate
something fundamental.

  reply	other threads:[~2010-09-27 17:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-27  8:53 [PATCH hail] lib/hstor.c: avoid an unconditional leak in append_qparam Jim Meyering
2010-09-27 16:29 ` Pete Zaitcev
2010-09-27 17:05   ` Jim Meyering [this message]
2010-09-28  0:23   ` Jeff Garzik
2010-09-27 16:53 ` Jeff Garzik
2010-09-28  0:24   ` Pete Zaitcev

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=87tylbt8us.fsf@meyering.net \
    --to=jim@meyering.net \
    --cc=hail-devel@vger.kernel.org \
    --cc=zaitcev@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 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.