Re: [HACKERS] Memory leak

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [HACKERS] Memory leak
Дата
Msg-id 27758.1501337187@sss.pgh.pa.us
обсуждение исходный текст
Ответ на [HACKERS] Memory leak  (fan yang <yangfangoto@gmail.com>)
Ответы Re: [HACKERS] Memory leak
Список pgsql-hackers
fan yang <yangfangoto@gmail.com> writes:
> - src/port/quotes.c
>     At line 38, at function "escape_single_quotes_ascii",
>     here used "malloc" to get some memory and return the
>     pointer returned by the "malloc".
>     So, any caller used this function shoule free this memory.
> - /src/bin/initdb/initdb.c
>     At line 327, at function "escape_quotes",
>     which use function "escape_single_quotes_ascii"
>     from above file.
>     But at this file(/src/bin/initdb/initdb.c), there are many place
>     used function "escape_quotes" but have not free the pointer returned
>     by the function, thus cause memory leak.

By and large, we intentionally don't worry about memory leaks in initdb
(or any other program with a limited runtime).  It's not worth the
maintenance effort to save a few bytes, at least not where it requires
code contortions like these.

Doing a quick check with valgrind says that a run of initdb, in HEAD,
leaks about 560KB over its lifespan.  That's well below the threshold
of pain on any machine capable of running modern Postgres reasonably.

For fun, I tried to see whether your patch moved that number appreciably,
but patch(1) couldn't make any sense of it at all.  I think that probably
your mail program munged the whitespace in the patch.  Many of us have
found that the most reliable way to forward patches through email is to
add them as attachments rather than pasting them into the text in-line.

Poking at it a bit harder with valgrind, it seems that the vast majority
of what it reports as leaks is caused by replace_token().  If we wanted to
reduce memory wastage during initdb, that would be the place to work on.
But I'm dubious that it's worth any effort.
        regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: fan yang
Дата:
Сообщение: [HACKERS] Memory leak
Следующее
От: Fan Yang
Дата:
Сообщение: Re: [HACKERS] Memory leak