Re: [PATCH] Memory leak, at src/common/exec.c

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [PATCH] Memory leak, at src/common/exec.c
Дата
Msg-id 27482.1576535596@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: [PATCH] Memory leak, at src/common/exec.c  (Mark Dilger <hornschnorter@gmail.com>)
Список pgsql-hackers
Mark Dilger <hornschnorter@gmail.com> writes:
> Please see the man page for putenv.  Are you certain it is safe to
> free the string passed to putenv after putenv returns?  I think this
> may be implemented differently on various platforms.

POSIX requires the behavior the glibc man page describes:

    The putenv() function shall use the string argument to set environment
    variable values. The string argument should point to a string of the
    form "name=value". The putenv() function shall make the value of
    the environment variable name equal to value by altering an existing
    variable or creating a new one. In either case, the string pointed to
    by string shall become part of the environment, so altering the string
    shall change the environment.

So yeah, that patch is completely wrong.  It might've survived light
testing with non-debug versions of malloc/free, but under any sort
of load the environment variable would become corrupted.  The reason
for the strdup in our code is exactly to make a long-lived string
that can safely be given to putenv.

            regards, tom lane



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

Предыдущее
От: Tomas Vondra
Дата:
Сообщение: Re: ERROR: could not resize shared memory segment...No space lefton device
Следующее
От: Ranier Vilela
Дата:
Сообщение: RE: [PATCH] Memory leak, at src/common/exec.c