Skip to content

Commit 1acab12

Browse files
committed
Remove memory leaks in isolationtester.
specscanner.l leaked a kilobyte of memory per token of the spec file. Apparently somebody thought that the introductory code block would be executed once; but it's once per yylex() call. A couple of functions in isolationtester.c leaked small amounts of memory due to not bothering to free one-time allocations. Might as well improve these so that valgrind gives this program a clean bill of health. Also get rid of an ugly static variable. Coverity complained about one of the one-time leaks, which led me to try valgrind'ing isolationtester, which led to discovery of the larger leak.
1 parent dcb0e24 commit 1acab12

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/test/isolation/isolationtester.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ static void exit_nicely(void) pg_attribute_noreturn();
5454
static void check_testspec(TestSpec *testspec);
5555
static void run_testspec(TestSpec *testspec);
5656
static void run_all_permutations(TestSpec *testspec);
57-
static void run_all_permutations_recurse(TestSpec *testspec, int nsteps,
58-
PermutationStep **steps);
57+
static void run_all_permutations_recurse(TestSpec *testspec, int *piles,
58+
int nsteps, PermutationStep **steps);
5959
static void run_named_permutations(TestSpec *testspec);
6060
static void run_permutation(TestSpec *testspec, int nsteps,
6161
PermutationStep **steps);
@@ -366,9 +366,9 @@ check_testspec(TestSpec *testspec)
366366
fprintf(stderr, "unused step name: %s\n", allsteps[i]->name);
367367
}
368368
}
369-
}
370369

371-
static int *piles;
370+
free(allsteps);
371+
}
372372

373373
/*
374374
* Run the permutations specified in the spec, or all if none were
@@ -393,6 +393,7 @@ run_all_permutations(TestSpec *testspec)
393393
int i;
394394
PermutationStep *steps;
395395
PermutationStep **stepptrs;
396+
int *piles;
396397

397398
/* Count the total number of steps in all sessions */
398399
nsteps = 0;
@@ -418,11 +419,16 @@ run_all_permutations(TestSpec *testspec)
418419
for (i = 0; i < testspec->nsessions; i++)
419420
piles[i] = 0;
420421

421-
run_all_permutations_recurse(testspec, 0, stepptrs);
422+
run_all_permutations_recurse(testspec, piles, 0, stepptrs);
423+
424+
free(steps);
425+
free(stepptrs);
426+
free(piles);
422427
}
423428

424429
static void
425-
run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **steps)
430+
run_all_permutations_recurse(TestSpec *testspec, int *piles,
431+
int nsteps, PermutationStep **steps)
426432
{
427433
int i;
428434
bool found = false;
@@ -444,7 +450,7 @@ run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **s
444450

445451
piles[i]++;
446452

447-
run_all_permutations_recurse(testspec, nsteps + 1, steps);
453+
run_all_permutations_recurse(testspec, piles, nsteps + 1, steps);
448454

449455
piles[i]--;
450456

src/test/isolation/specscanner.l

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,12 @@ self [,()*]
5252
%%
5353

5454
%{
55-
litbuf = pg_malloc(LITBUF_INIT);
56-
litbufsize = LITBUF_INIT;
55+
/* Allocate litbuf in first call of yylex() */
56+
if (litbuf == NULL)
57+
{
58+
litbuf = pg_malloc(LITBUF_INIT);
59+
litbufsize = LITBUF_INIT;
60+
}
5761
%}
5862

5963
/* Keywords (must appear before the {identifier} rule!) */

0 commit comments

Comments
 (0)