Get rid of hacky usage of pgut_strdup() in utoa.

From inspecting the call sites of utoa, it appears that some of them
(especially the recent cleanup patch which added the strdup there) wanted
to prevent overwriting a local variable by repeated call (to utoa) using
the same variable as argument. This commit instead makes such call sites
strdup the variable itself before passing it to utoa. That seems cleaner
considering that it does not seem utoa's contract to do so (strdup its
parameter that is).
This commit is contained in:
amit 2015-05-27 11:11:15 +09:00
parent d3a99db9f9
commit 775a97dbd9

View File

@ -243,13 +243,8 @@ static char *
utoa(unsigned int value, char *buffer)
{
sprintf(buffer, "%u", value);
/* XXX: originally, we would just return buffer here without
* the pgut_strdup(). But repack_cleanup_callback() seems to
* depend on getting back a freshly strdup'd copy of buffer,
* not sure why. So now we are leaking a tiny bit of memory
* with each utoa() call.
*/
return pgut_strdup(buffer);
return buffer;
}
static pgut_option options[] =
@ -1397,7 +1392,7 @@ repack_one_table(repack_table *table, const char *orderby)
elog(DEBUG2, "---- drop ----");
command("BEGIN ISOLATION LEVEL READ COMMITTED", 0, NULL);
params[1] = utoa(temp_obj_num, buffer);
params[1] = utoa(temp_obj_num, pgut_strdup(buffer));
command("SELECT repack.repack_drop($1, $2)", 2, params);
command("COMMIT", 0, NULL);
temp_obj_num = 0; /* reset temporary object counter after cleanup */
@ -1419,7 +1414,7 @@ repack_one_table(repack_table *table, const char *orderby)
/* Release advisory lock on table. */
params[0] = REPACK_LOCK_PREFIX_STR;
params[1] = utoa(table->target_oid, buffer);
params[1] = utoa(table->target_oid, pgut_strdup(buffer));
res = pgut_execute(connection, "SELECT pg_advisory_unlock($1, CAST(-2147483648 + $2::bigint AS integer))",
2, params);
@ -1712,7 +1707,7 @@ repack_cleanup_callback(bool fatal, void *userdata)
if(fatal)
{
params[0] = utoa(target_table, buffer);
params[1] = utoa(temp_obj_num, buffer);
params[1] = utoa(temp_obj_num, pgut_strdup(buffer));
/* testing PQstatus() of connection and conn2, as we do
* in repack_cleanup(), doesn't seem to work here,
@ -1747,7 +1742,7 @@ repack_cleanup(bool fatal, const repack_table *table)
/* do cleanup */
params[0] = utoa(table->target_oid, buffer);
params[1] = utoa(temp_obj_num, buffer);
params[1] = utoa(temp_obj_num, pgut_strdup(buffer));
command("SELECT repack.repack_drop($1, $2)", 2, params);
temp_obj_num = 0; /* reset temporary object counter after cleanup */
}