Re: memory leaking ?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: memory leaking ?
Дата
Msg-id 8787.1401302268@sss.pgh.pa.us
обсуждение исходный текст
Ответ на memory leaking ?  (Zhemin Zhou <Zhemin.Zhou@warwick.ac.uk>)
Список pgsql-general
Zhemin Zhou <Zhemin.Zhou@warwick.ac.uk> writes:
> We met a problem after running the website for one week. We used a
> function to convert and save binary files into the database (as bytea).
> This function worked well in the old version but sometimes makes the new
> version of postgres crash. This random crash is not file specific.

AFAICT, it's pure luck that it didn't crash the older system too.  You're
allocating the output buffer too small, at least for cases where "size"
isn't a multiple of 3:

>      bytea *result = (bytea *)
> palloc(VARHDRSZ+sizeof(char)*(4*(size)/3+15));

For example, if size = 2, 4*2/3 is only 2, but the loop will write 4 bytes
of data.  So the function sometimes clobbers bytes beyond what it
allocated, which unsurprisingly corrupts malloc's data structures.
You need to round up not truncate in this division.

            regards, tom lane


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

Предыдущее
От: Marc Brazeau
Дата:
Сообщение: log_collector & sysout on windows
Следующее
От: Shaun Thomas
Дата:
Сообщение: Re: Conversion from CHAR HEX