BUG #15103: Do not use pfree() to free pg_malloc() return value in vacuum_one_database()

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: bianpan2016(at)163(dot)com
Subject: BUG #15103: Do not use pfree() to free pg_malloc() return value in vacuum_one_database()
Date: 2018-03-09 01:32:47
Message-ID: 152055916778.4972.13890764985392726175@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 15103
Logged by: Pan Bian
Email address: bianpan2016(at)163(dot)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 }

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2018-03-09 01:48:40 BUG #15104: Double free in the main function in ecpg.c
Previous Message Chris Travers 2018-03-08 18:37:29 When using multiple inheritance, insufficient tests exist for whether a data type change is safe.