Skip to content

Commit b6b6a8b

Browse files
committed
Merge branch 'master' of https://github.com/kotsachin/pg_repack into kotsachin-master
2 parents 4e69428 + 8a0466e commit b6b6a8b

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

bin/pg_repack.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static char *
243243
utoa(unsigned int value, char *buffer)
244244
{
245245
sprintf(buffer, "%u", value);
246-
return strdup(buffer);
246+
return pgut_strdup(buffer);
247247
}
248248

249249
static pgut_option options[] =
@@ -1391,6 +1391,7 @@ repack_one_table(repack_table *table, const char *orderby)
13911391
params[1] = utoa(temp_obj_num, buffer);
13921392
command("SELECT repack.repack_drop($1, $2)", 2, params);
13931393
command("COMMIT", 0, NULL);
1394+
temp_obj_num = 0; /* reset temporary object counter after cleanup */
13941395

13951396
/*
13961397
* 7. Analyze.
@@ -1706,6 +1707,7 @@ repack_cleanup_callback(bool fatal, void *userdata)
17061707

17071708
reconnect(ERROR);
17081709
command("SELECT repack.repack_drop($1, $2)", 2, params);
1710+
temp_obj_num = 0; /* reset temporary object counter after cleanup */
17091711
}
17101712
}
17111713

@@ -1734,6 +1736,7 @@ repack_cleanup(bool fatal, const repack_table *table)
17341736
params[0] = utoa(table->target_oid, buffer);
17351737
params[1] = utoa(temp_obj_num, buffer);
17361738
command("SELECT repack.repack_drop($1, $2)", 2, params);
1739+
temp_obj_num = 0; /* reset temporary object counter after cleanup */
17371740
}
17381741
}
17391742

bin/pgut/pgut.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void on_before_exec(pgutConn *conn);
6464
static void on_after_exec(pgutConn *conn);
6565
static void on_interrupt(void);
6666
static void on_cleanup(void);
67-
static void exit_or_abort(int exitcode);
67+
static void exit_or_abort(int exitcode, int elevel);
6868

6969
void
7070
pgut_init(int argc, char **argv)
@@ -872,7 +872,10 @@ pgut_errfinish(int dummy, ...)
872872
edata->detail.data);
873873

874874
if (pgut_abort_level <= edata->elevel && edata->elevel <= PANIC)
875-
exit_or_abort(edata->code);
875+
{
876+
in_cleanup = true; /* need to be set for cleaning temporary objects on error */
877+
exit_or_abort(edata->code, edata->elevel);
878+
}
876879
}
877880

878881
#ifndef PGUT_OVERRIDE_ELOG
@@ -1195,13 +1198,19 @@ on_cleanup(void)
11951198
}
11961199

11971200
static void
1198-
exit_or_abort(int exitcode)
1201+
exit_or_abort(int exitcode, int elevel)
11991202
{
1200-
call_atexit_callbacks(true);
1201-
if (in_cleanup)
1203+
1204+
if (in_cleanup && FATAL > elevel)
12021205
{
12031206
/* oops, error in cleanup*/
1204-
in_cleanup = false;
1207+
call_atexit_callbacks(true);
1208+
exit(exitcode);
1209+
}
1210+
else if (FATAL <= elevel <= PANIC)
1211+
{
1212+
/* on FATAL or PANIC */
1213+
call_atexit_callbacks(true);
12051214
abort();
12061215
}
12071216
else

0 commit comments

Comments
 (0)