Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bc031cf

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 aa2734f commit bc031cf

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
@@ -53,8 +53,8 @@ static int64 max_step_wait = 300 * USECS_PER_SEC;
5353
static void check_testspec(TestSpec *testspec);
5454
static void run_testspec(TestSpec *testspec);
5555
static void run_all_permutations(TestSpec *testspec);
56-
static void run_all_permutations_recurse(TestSpec *testspec, int nsteps,
57-
PermutationStep **steps);
56+
static void run_all_permutations_recurse(TestSpec *testspec, int *piles,
57+
int nsteps, PermutationStep **steps);
5858
static void run_named_permutations(TestSpec *testspec);
5959
static void run_permutation(TestSpec *testspec, int nsteps,
6060
PermutationStep **steps);
@@ -361,9 +361,9 @@ check_testspec(TestSpec *testspec)
361361
fprintf(stderr, "unused step name: %s\n", allsteps[i]->name);
362362
}
363363
}
364-
}
365364

366-
static int *piles;
365+
free(allsteps);
366+
}
367367

368368
/*
369369
* Run the permutations specified in the spec, or all if none were
@@ -388,6 +388,7 @@ run_all_permutations(TestSpec *testspec)
388388
int i;
389389
PermutationStep *steps;
390390
PermutationStep **stepptrs;
391+
int *piles;
391392

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

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

419424
static void
420-
run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **steps)
425+
run_all_permutations_recurse(TestSpec *testspec, int *piles,
426+
int nsteps, PermutationStep **steps)
421427
{
422428
int i;
423429
bool found = false;
@@ -439,7 +445,7 @@ run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **s
439445

440446
piles[i]++;
441447

442-
run_all_permutations_recurse(testspec, nsteps + 1, steps);
448+
run_all_permutations_recurse(testspec, piles, nsteps + 1, steps);
443449

444450
piles[i]--;
445451

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)