10000 Remove memory leaks in isolationtester. · postgres/postgres@7676d95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7676d95

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 f5b780c commit 7676d95

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);
@@ -365,9 +365,9 @@ check_testspec(TestSpec *testspec)
365365
fprintf(stderr, "unused step name: %s\n", allsteps[i]->name);
366366
}
367367
}
368-
}
369368

370-
static int *piles;
369+
free(allsteps);
370+
}
371371

372372
/*
373373
* Run the permutations specified in the spec, or all if none were
@@ -392,6 +392,7 @@ run_all_permutations(TestSpec *testspec)
392392
int i;
393393
PermutationStep *steps;
394394
PermutationStep **stepptrs;
395+
int *piles;
395396

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

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

423428
static void
424-
run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **steps)
429+
run_all_permutations_recurse(TestSpec *testspec, int *piles,
430+
int nsteps, PermutationStep **steps)
425431
{
426432
int i;
427433
bool found = false;
@@ -443,7 +449,7 @@ run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **s
443449

444450
piles[i]++;
445451

446-
run_all_permutations_recurse(testspec, nsteps + 1, steps);
452+
run_all_permutations_recurse(testspec, piles, nsteps + 1, steps);
447453

448454
piles[i]--;
449455

src/test/isolation/specscanner.l

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

5252
%{
53-
litbuf = pg_malloc(LITBUF_INIT);
54-
litbufsize = LITBUF_INIT;
53+
/* Allocate litbuf in first call of yylex() */
54+
if (litbuf == NULL)
55+
{
56+
litbuf = pg_malloc(LITBUF_INIT);
57+
litbufsize = LITBUF_INIT;
58+
}
5559
%}
5660

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

0 commit comments

Comments
 (0)
0