Re: libpq: fix unlikely memory leak

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: libpq: fix unlikely memory leak
Дата
Msg-id 9344.1120056501@sss.pgh.pa.us
обсуждение исходный текст
Ответ на libpq: fix unlikely memory leak  (Neil Conway <neilc@samurai.com>)
Ответы Re: libpq: fix unlikely memory leak  (Neil Conway <neilc@samurai.com>)
Список pgsql-patches
Neil Conway <neilc@samurai.com> writes:
> The attached patch fixes a theoretical memory leak in libpq: if the
> second malloc() fails due to OOM, the memory returned by the first
> (successful) malloc() will be leaked.

Since both allocations are only transient within this routine, there's
a simpler more effective solution, which is to only do one malloc in
the first place:

                  char       *crypt_pwd2;

                  /* need enough space for 2 MD5 hashes */
                  if (!(crypt_pwd = malloc(2 * (MD5_PASSWD_LEN + 1))))
                  {
                      fprintf(stderr, libpq_gettext("out of memory\n"));
                      return STATUS_ERROR;
                  }
                  crypt_pwd2 = crypt_pwd + (MD5_PASSWD_LEN + 1);

and drop the free(crypt_pwd2) calls.

            regards, tom lane

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

Предыдущее
От: "Andrew Dunstan"
Дата:
Сообщение: Re: plperl features
Следующее
От: Stephen Frost
Дата:
Сообщение: Change Ownership Permission Checks