Skip to content

Commit 642c069

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 c302a61 commit 642c069

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/test/isolation/isolationtester.c

+13-7
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static int64 max_step_wait = 300 * USECS_PER_SEC;
5252
static void check_testspec(TestSpec *testspec);
5353
static void run_testspec(TestSpec *testspec);
5454
static void run_all_permutations(TestSpec *testspec);
55-
static void run_all_permutations_recurse(TestSpec *testspec, int nsteps,
56-
PermutationStep **steps);
55+
static void run_all_permutations_recurse(TestSpec *testspec, int *piles,
56+
int nsteps, PermutationStep **steps);
5757
static void run_named_permutations(TestSpec *testspec);
5858
static void run_permutation(TestSpec *testspec, int nsteps,
5959
PermutationStep **steps);
@@ -360,9 +360,9 @@ check_testspec(TestSpec *testspec)
360360
fprintf(stderr, "unused step name: %s\n", allsteps[i]->name);
361361
}
362362
}
363-
}
364363

365-
static int *piles;
364+
free(allsteps);
365+
}
366366

367367
/*
368368
* Run the permutations specified in the spec, or all if none were
@@ -387,6 +387,7 @@ run_all_permutations(TestSpec *testspec)
387387
int i;
388388
PermutationStep *steps;
389389
PermutationStep **stepptrs;
390+
int *piles;
390391

391392
/* Count the total number of steps in all sessions */
392393
nsteps = 0;
@@ -412,11 +413,16 @@ run_all_permutations(TestSpec *testspec)
412413
for (i = 0; i < testspec->nsessions; i++)
413414
piles[i] = 0;
414415

415-
run_all_permutations_recurse(testspec, 0, stepptrs);
416+
run_all_permutations_recurse(testspec, piles, 0, stepptrs);
417+
418+
free(steps);
419+
free(stepptrs);
420+
free(piles);
416421
}
417422

418423
static void
419-
run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **steps)
424+
run_all_permutations_recurse(TestSpec *testspec, int *piles,
425+
int nsteps, PermutationStep **steps)
420426
{
421427
int i;
422428
bool found = false;
@@ -438,7 +444,7 @@ run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **s
438444

439445
piles[i]++;
440446

441-
run_all_permutations_recurse(testspec, nsteps + 1, steps);
447+
run_all_permutations_recurse(testspec, piles, nsteps + 1, steps);
442448

443449
piles[i]--;
444450

src/test/isolation/specscanner.l

+6-2
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)