Skip to content

Commit e3495ee

Browse files
authored
Merge pull request #1204 from matejak/cov-18
Fixed a memory leak, introduced Stable_free.
2 parents 9d183c5 + 363bccf commit e3495ee

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/OVAL/probes/SEAP/seap-command-backendS.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ static Stable_t *Stable_new (size_t capacity)
8585
return (t);
8686
}
8787

88+
static void Stable_free(Stable_t *table)
89+
{
90+
if (table != NULL) {
91+
for (i = 0; i < table->t_size; ++i) {
92+
if (table->t_recs[i].c_size > 0)
93+
sm_free(table->t_recs[i].c_recs);
94+
}
95+
96+
sm_free(table->t_recs);
97+
sm_free(table);
98+
}
99+
}
100+
88101
static int Stable_add (Stable_t *t, SEAP_cmdrec_t *r)
89102
{
90103
Stable_rec_t *t_r;
@@ -138,10 +151,11 @@ int SEAP_cmdtbl_backendS_add (SEAP_cmdtbl_t *t, SEAP_cmdrec_t *r)
138151
n = Stable_new (SEAP_CMDTBL_LARGE_TRESHOLD);
139152
ret = SEAP_cmdtbl_backendL_apply (t, &Stable_conv, (void *)n);
140153

141-
if (ret != 0) {
142-
SEAP_cmdtbl_backendS_free (t);
143-
return (ret);
144-
}
154+
if (ret != 0) {
155+
SEAP_cmdtbl_backendS_free(t);
156+
Stable_free(n);
157+
return ret;
158+
}
145159

146160
SEAP_cmdtbl_backendL_free (t);
147161
t->table = n;
@@ -180,24 +194,17 @@ int SEAP_cmdtbl_backendS_cmp (SEAP_cmdrec_t *a, SEAP_cmdrec_t *b)
180194
return (a->code - b->code);
181195
}
182196

183-
void SEAP_cmdtbl_backendS_free (SEAP_cmdtbl_t *t)
197+
void SEAP_cmdtbl_backendS_free(SEAP_cmdtbl_t *t)
184198
{
185199
size_t i;
186200
Stable_t *St;
187-
201+
188202
St = (Stable_t *)(t->table);
189-
190-
if (St != NULL) {
191-
for (i = 0; i < St->t_size; ++i)
192-
if (St->t_recs[i].c_size > 0)
193-
sm_free (St->t_recs[i].c_recs);
194-
195-
sm_free (St->t_recs);
196-
sm_free (St);
197-
198-
t->table = NULL;
199-
}
200-
return;
203+
204+
if (St != NULL) {
205+
Stable_free(St);
206+
t->table = NULL;
207+
}
201208
}
202209

203210
int SEAP_cmdtbl_backendS_apply (SEAP_cmdtbl_t *t, int (*func) (SEAP_cmdrec_t *r, void *), void *arg)

0 commit comments

Comments
 (0)