Is it memory leak or not?

Started by Dmitry Igrishinalmost 6 years ago3 messages
#1Dmitry Igrishin
dmitigr@gmail.com

Hello,

Maybe I'm wrong, but anychar_typmodin() of
src/backend/utils/adt/varchar.c of PostgreSQL 12.1 does not pfree()s
the memory allocated by ArrayGetIntegerTypmods(). Probably, I'm
missing something. Could anybody please clarify on that?

Thanks!

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Dmitry Igrishin (#1)
Re: Is it memory leak or not?

Dmitry Igrishin <dmitigr@gmail.com> writes:

Maybe I'm wrong, but anychar_typmodin() of
src/backend/utils/adt/varchar.c of PostgreSQL 12.1 does not pfree()s
the memory allocated by ArrayGetIntegerTypmods(). Probably, I'm
missing something. Could anybody please clarify on that?

It is a leak, in the sense that the pointer is unreferenced once the
function returns. But we don't care, either here or in the probably
thousands of other similar cases, because we don't expect this function
to be run in a long-lived memory context. The general philosophy in
the backend is that it's cheaper and far less error-prone to rely on
memory context cleanup to reclaim (small amounts of) memory than to
rely on manual pfree calls. You can read more about that in
src/backend/utils/mmgr/README.

regards, tom lane

#3Dmitry Igrishin
dmitigr@gmail.com
In reply to: Tom Lane (#2)
Re: Is it memory leak or not?

On Mon, 10 Feb 2020, 18:59 Tom Lane, <tgl@sss.pgh.pa.us> wrote:

Dmitry Igrishin <dmitigr@gmail.com> writes:

Maybe I'm wrong, but anychar_typmodin() of
src/backend/utils/adt/varchar.c of PostgreSQL 12.1 does not pfree()s
the memory allocated by ArrayGetIntegerTypmods(). Probably, I'm
missing something. Could anybody please clarify on that?

It is a leak, in the sense that the pointer is unreferenced once the
function returns. But we don't care, either here or in the probably
thousands of other similar cases, because we don't expect this function
to be run in a long-lived memory context. The general philosophy in
the backend is that it's cheaper and far less error-prone to rely on
memory context cleanup to reclaim (small amounts of) memory than to
rely on manual pfree calls. You can read more about that in
src/backend/utils/mmgr/README.

I see. Thank you very much!