mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-01 01:47:25 +02:00
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.
This commit is contained in:
parent
dcb0e243dd
commit
1acab12096
@ -54,8 +54,8 @@ static void exit_nicely(void) pg_attribute_noreturn();
|
|||||||
static void check_testspec(TestSpec *testspec);
|
static void check_testspec(TestSpec *testspec);
|
||||||
static void run_testspec(TestSpec *testspec);
|
static void run_testspec(TestSpec *testspec);
|
||||||
static void run_all_permutations(TestSpec *testspec);
|
static void run_all_permutations(TestSpec *testspec);
|
||||||
static void run_all_permutations_recurse(TestSpec *testspec, int nsteps,
|
static void run_all_permutations_recurse(TestSpec *testspec, int *piles,
|
||||||
PermutationStep **steps);
|
int nsteps, PermutationStep **steps);
|
||||||
static void run_named_permutations(TestSpec *testspec);
|
static void run_named_permutations(TestSpec *testspec);
|
||||||
static void run_permutation(TestSpec *testspec, int nsteps,
|
static void run_permutation(TestSpec *testspec, int nsteps,
|
||||||
PermutationStep **steps);
|
PermutationStep **steps);
|
||||||
@ -366,9 +366,9 @@ check_testspec(TestSpec *testspec)
|
|||||||
fprintf(stderr, "unused step name: %s\n", allsteps[i]->name);
|
fprintf(stderr, "unused step name: %s\n", allsteps[i]->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static int *piles;
|
free(allsteps);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Run the permutations specified in the spec, or all if none were
|
* Run the permutations specified in the spec, or all if none were
|
||||||
@ -393,6 +393,7 @@ run_all_permutations(TestSpec *testspec)
|
|||||||
int i;
|
int i;
|
||||||
PermutationStep *steps;
|
PermutationStep *steps;
|
||||||
PermutationStep **stepptrs;
|
PermutationStep **stepptrs;
|
||||||
|
int *piles;
|
||||||
|
|
||||||
/* Count the total number of steps in all sessions */
|
/* Count the total number of steps in all sessions */
|
||||||
nsteps = 0;
|
nsteps = 0;
|
||||||
@ -418,11 +419,16 @@ run_all_permutations(TestSpec *testspec)
|
|||||||
for (i = 0; i < testspec->nsessions; i++)
|
for (i = 0; i < testspec->nsessions; i++)
|
||||||
piles[i] = 0;
|
piles[i] = 0;
|
||||||
|
|
||||||
run_all_permutations_recurse(testspec, 0, stepptrs);
|
run_all_permutations_recurse(testspec, piles, 0, stepptrs);
|
||||||
|
|
||||||
|
free(steps);
|
||||||
|
free(stepptrs);
|
||||||
|
free(piles);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **steps)
|
run_all_permutations_recurse(TestSpec *testspec, int *piles,
|
||||||
|
int nsteps, PermutationStep **steps)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@ -444,7 +450,7 @@ run_all_permutations_recurse(TestSpec *testspec, int nsteps, PermutationStep **s
|
|||||||
|
|
||||||
piles[i]++;
|
piles[i]++;
|
||||||
|
|
||||||
run_all_permutations_recurse(testspec, nsteps + 1, steps);
|
run_all_permutations_recurse(testspec, piles, nsteps + 1, steps);
|
||||||
|
|
||||||
piles[i]--;
|
piles[i]--;
|
||||||
|
|
||||||
|
@ -52,8 +52,12 @@ self [,()*]
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
%{
|
%{
|
||||||
litbuf = pg_malloc(LITBUF_INIT);
|
/* Allocate litbuf in first call of yylex() */
|
||||||
litbufsize = LITBUF_INIT;
|
if (litbuf == NULL)
|
||||||
|
{
|
||||||
|
litbuf = pg_malloc(LITBUF_INIT);
|
||||||
|
litbufsize = LITBUF_INIT;
|
||||||
|
}
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/* Keywords (must appear before the {identifier} rule!) */
|
/* Keywords (must appear before the {identifier} rule!) */
|
||||||
|
Loading…
Reference in New Issue
Block a user