Re: any suggestions to detect memory corruption

From: Alex <zhihui(dot)fan1213(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: any suggestions to detect memory corruption
Date: 2019-05-10 00:52:45
Message-ID: CAKU4AWofge-TygReXWM5RH0c5SXBBqWX9FhJBcqZpeqzCOvVyA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, May 9, 2019 at 9:30 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Alex <zhihui(dot)fan1213(at)gmail(dot)com> writes:
> > Someone add some code during backend init which used palloc. but at that
> > time, the CurrentMemoryContext is PostmasterContext. at the end of
> > backend initialization, the PostmasterContext is deleted, then the error
> > happens. the reason why it happens randomly is before the palloc, there
> > are some other if clause which may skip the palloc.
>
> > I still can't explain why PostmasterContext may have impact "index info"
> > MemoryContext sometime, but now I just can't reproduce it (before the
> > fix, it may happen in 30% cases).
>
> Well, once the context is deleted, that memory is available for reuse.
> Everything will seem fine until it *is* reused, and then boom!
>
> The error would have been a lot more obvious if you'd enabled
> MEMORY_CONTEXT_CHECKING, which would overwrite freed data with garbage.
>

Thanks! I didn't know this before and " once the context is deleted,
that memory is available for reuse.
Everything will seem fine until it *is* reused". I have enabled
enable-cassert now.

That is normally turned on in --enable-cassert builds. Anybody who's been
> hacking Postgres for more than a week does backend code development in
> --enable-cassert mode as a matter of course; it turns on a *lot* of
> helpful cross-checks.
>
>

> regards, tom lane
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2019-05-10 01:02:51 Re: pg12 release notes
Previous Message Bruce Momjian 2019-05-10 00:38:39 Re: pg12 release notes