git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: "Carlo Arenas" <carenas@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/3] grep: plug leak of pcre chartables in PCRE2
Date: Mon, 29 Jul 2019 22:34:52 +0200
Message-ID: <7ec60d57-9940-35f2-f7b5-c87d4dc7cdd5@web.de> (raw)
In-Reply-To: <CAPUEspgowrhj56SzW8cPKjZL28nPTkX-RScKrSAai8i0YkwFaA@mail.gmail.com>

Am 28.07.19 um 03:41 schrieb Carlo Arenas:
> On Sat, Jul 27, 2019 at 4:48 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>>> +     free((void *)p->pcre_tables);
>>
>> Is the cast really needed? I'm rusty on the rules, removing it from the
>> pcre_free() you might have copied this from produces a warning for me,
>> but not for free() itself. This is on GCC 8.3.0. How about for you &
>> what compiler(s)?
>
> both will trigger warnings for the same reason
> (-Wincompatible-pointer-types-discards-qualifiers)
> with Apple LLVM version 10.0.1 (clang-1001.0.46.4)
>
> gcc-9 in macOS triggers 2 "warnings"; one for discarding the const
> qualifier (-Wdiscarded-qualifiers)
> and another for mismatching parameter to free():
>
> note: expected 'void *' but argument is of type 'const uint8_t *' {aka
> 'const unsigned char *'}

Right: pcre_maketables() returns a const pointer, and you have to cast
away this const'ness at some point if you want to free(3) that memory.
Returning a non-const pointer would be more fitting, but I guess the
idea is that users of the library are not supposed to change the
contents of the table.

But wouldn't it be more correct to use pcre_free()?  As long as we keep
pcre_malloc() and pcre_free() at their default values it doesn't matter
in practice, but using free(3) directly is a layering violation, no?

Perhaps just UNLEAK that thing?  There is only a single way to build it
and we can reuse it throughout the lifetime of the program, so there is
no real need to clean it up before the OS does.

René

  reply	other threads:[~2019-07-29 20:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-27 20:27 [PATCH 0/3] grep: memory leak " Carlo Marcelo Arenas Belón
2019-07-27 20:27 ` [PATCH 1/3] grep: make pcre1_tables version agnostic Carlo Marcelo Arenas Belón
2019-07-27 23:47   ` Ævar Arnfjörð Bjarmason
2019-07-28  2:50     ` Carlo Arenas
2019-07-27 20:27 ` [PATCH 2/3] grep: use pcre_tables also for PCRE2 Carlo Marcelo Arenas Belón
2019-07-27 20:27 ` [PATCH 3/3] grep: plug leak of pcre chartables in PCRE2 Carlo Marcelo Arenas Belón
2019-07-27 23:48   ` Ævar Arnfjörð Bjarmason
2019-07-28  1:41     ` Carlo Arenas
2019-07-29 20:34       ` René Scharfe [this message]
2019-07-30  0:08         ` Carlo Arenas
2019-07-30 16:52           ` René Scharfe
2019-08-01 17:09 ` [PATCH v2] grep: avoid leak of " Carlo Marcelo Arenas Belón
2019-08-02 16:19   ` Junio C Hamano
2019-08-03 18:50     ` Carlo Arenas
2019-08-05 19:34       ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=7ec60d57-9940-35f2-f7b5-c87d4dc7cdd5@web.de \
    --to=l.s.r@web.de \
    --cc=avarab@gmail.com \
    --cc=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    /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

git@vger.kernel.org list mirror (unofficial, one of many)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 git git/ https://public-inbox.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.io/gmane.comp.version-control.git
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git