pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Finding memory corruption in an extension
3+ messages / 3 participants
[nested] [flat]

* Finding memory corruption in an extension
@ 2021-01-08 17:47  Jack Orenstein <jao@geophile.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Jack Orenstein @ 2021-01-08 17:47 UTC (permalink / raw)
  To: pgsql-general

An extension I'm creating is causing Postgres to crash, almost certainly
due to memory corruption.  I am using palloc0/pfree, calling SET_VARSIZE,
and generally following the procedures documented here:
https://www.postgresql.org/docs/12/xfunc-c.html. I am also testing my code
outside of Postgres (using alloc/free instead of palloc0/pfree), and
valgrind is not finding any corruption or leaks.

The crash is not completely reproducible, but when it does happen, it's
pretty fast -- create a table, insert a couple of rows, explain a query.
(My goal is to create a GIN index on my datatype, but this crash occurs
without the index.)

I'm interested in advice on how to go about hunting down my problem.
Something along the lines of a debugging malloc, or valgrind, for Postgres.

Jack Orenstein

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Finding memory corruption in an extension
@ 2021-01-08 17:53  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Jack Orenstein <jao@geophile.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Pavel Stehule @ 2021-01-08 17:53 UTC (permalink / raw)
  To: Jack Orenstein <jao@geophile.com>; +Cc: pgsql-general

Hi

pá 8. 1. 2021 v 18:48 odesílatel Jack Orenstein <jao@geophile.com> napsal:

> An extension I'm creating is causing Postgres to crash, almost certainly
> due to memory corruption.  I am using palloc0/pfree, calling SET_VARSIZE,
> and generally following the procedures documented here:
> https://www.postgresql.org/docs/12/xfunc-c.html. I am also testing my
> code outside of Postgres (using alloc/free instead of palloc0/pfree), and
> valgrind is not finding any corruption or leaks.
>
> The crash is not completely reproducible, but when it does happen, it's
> pretty fast -- create a table, insert a couple of rows, explain a query.
> (My goal is to create a GIN index on my datatype, but this crash occurs
> without the index.)
>
> I'm interested in advice on how to go about hunting down my problem.
> Something along the lines of a debugging malloc, or valgrind, for Postgres.
>

The basic feature is using postgres compiled with --enable-cassert flag. It
does lot of checks of memory corruptions

Regards

Pavel




> Jack Orenstein
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Finding memory corruption in an extension
@ 2021-01-08 18:28  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2021-01-08 18:28 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: Jack Orenstein <jao@geophile.com>; pgsql-general

Pavel Stehule <pavel.stehule@gmail.com> writes:
> pá 8. 1. 2021 v 18:48 odesílatel Jack Orenstein <jao@geophile.com> napsal:
>> I'm interested in advice on how to go about hunting down my problem.
>> Something along the lines of a debugging malloc, or valgrind, for Postgres.

> The basic feature is using postgres compiled with --enable-cassert flag. It
> does lot of checks of memory corruptions

Yeah, you should absolutely use --enable-cassert when working on C code.

If you need valgrind, there's advice about how to run it at

https://wiki.postgresql.org/wiki/Valgrind

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2021-01-08 18:28 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-08 17:47 Finding memory corruption in an extension Jack Orenstein <jao@geophile.com>
2021-01-08 17:53 ` Pavel Stehule <pavel.stehule@gmail.com>
2021-01-08 18:28   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox