Обсуждение: BUG #15103: Do not use pfree() to free pg_malloc() return value invacuum_one_database()
BUG #15103: Do not use pfree() to free pg_malloc() return value invacuum_one_database()
От
PG Bug reporting form
Дата:
The following bug has been logged on the website:
Bug reference: 15103
Logged by: Pan Bian
Email address: bianpan2016@163.com
PostgreSQL version: 10.3
Operating system: Linux
Description:
File: src/bin/scripts/vacuumdb.c
Function: vacuum_one_database()
Details: In function vacuum_one_database(), the memory allocated with
pg_malloc() (at line 435), but the return value is freed with pfree() (at
line 530). I think use the function pg_free() paired with pg_malloc() is
better here.
For your convenience, I paste related bugs as follows:
334 static void
335 vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
336 int stage,
337 SimpleStringList *tables,
338 const char *host, const char *port,
339 const char *username, enum trivalue
prompt_password,
340 int concurrentCons,
341 const char *progname, bool echo, bool quiet)
342 {
343 PQExpBufferData sql;
344 PGconn *conn;
345 SimpleStringListCell *cell;
346 ParallelSlot *slots = NULL;
...
435 slots = (ParallelSlot *) pg_malloc(sizeof(ParallelSlot) *
concurrentCons);
436 init_slot(slots, conn, progname);
437 if (parallel)
438 {
439 for (i = 1; i < concurrentCons; i++)
440 {
441 conn = connectDatabase(dbname, host, port, username,
prompt_password,
442 progname, echo, false, true);
443 init_slot(slots + i, conn, progname);
444 }
445 }
...
527 finish:
528 for (i = 0; i < concurrentCons; i++)
529 DisconnectDatabase(slots + i);
530 pfree(slots);
531
532 termPQExpBuffer(&sql);
533
534 if (failed)
535 exit(1);
536 }
Re: BUG #15103: Do not use pfree() to free pg_malloc() return valuein vacuum_one_database()
От
Michael Paquier
Дата:
On Fri, Mar 09, 2018 at 01:32:47AM +0000, PG Bug reporting form wrote: > Details: In function vacuum_one_database(), the memory allocated with > pg_malloc() (at line 435), but the return value is freed with pfree() (at > line 530). I think use the function pg_free() paired with pg_malloc() is > better here. In practice it does not matter much as pfree is just a wrapper on top of pg_free(). Please see fe_memutils.c, which lists all the memory-related APIs for frontends. -- Michael