Skip to content

Commit 7547955

Browse files
Sergei Ianovichyanovich
authored andcommitted
fix memory leaks
Signed-off-by: Sergei Ianovich <s@elektroplus.ru>
1 parent 228e0b9 commit 7547955

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

gost_eng.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ static int gost_engine_finish(ENGINE* e) {
297297
return 1;
298298
}
299299

300+
static void free_NIDs();
301+
300302
static int gost_engine_destroy(ENGINE* e) {
301303
int i;
302304

@@ -314,6 +316,7 @@ static int gost_engine_destroy(ENGINE* e) {
314316
}
315317

316318
free_cached_groups();
319+
free_NIDs();
317320

318321
# ifndef BUILDING_GOST_PROVIDER
319322
ERR_unload_GOST_strings();
@@ -339,6 +342,7 @@ static int create_NIDs() {
339342
GOST_NID_JOB *job = missing_NIDs[i];
340343
ASN1_OBJECT *obj =
341344
ASN1_OBJECT_create(new_nid + i, NULL, 0, job->sn, job->ln);
345+
job->asn1 = obj;
342346
if (!obj || OBJ_add_object(obj) == NID_undef) {
343347
OPENSSL_free(obj);
344348
fprintf(stderr, "failed NID for %s\n", job->sn);
@@ -349,6 +353,13 @@ static int create_NIDs() {
349353
return 1;
350354
}
351355

356+
static void free_NIDs() {
357+
int i;
358+
for (i = 0; i < OSSL_NELEM(missing_NIDs); i++) {
359+
ASN1_OBJECT_free(missing_NIDs[i]->asn1);
360+
}
361+
}
362+
352363
# ifndef BUILDING_GOST_PROVIDER
353364
static
354365
# endif

gost_lcl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ struct gost_nid_job {
408408
const char *sn;
409409
const char *ln;
410410
void (*callback)(int nid);
411+
ASN1_OBJECT *asn1;
411412
};
412413

413414
typedef struct gost_nid_job GOST_NID_JOB;

test_mgm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ int main(void)
243243

244244
for (t = testcases; t->sn; t++) {
245245
int small;
246-
const EVP_CIPHER *ciph = EVP_get_cipherbyname(t->sn);
246+
EVP_CIPHER *ciph = (EVP_CIPHER *) EVP_get_cipherbyname(t->sn);
247247
const char *name;
248248
if (!ciph) {
249249
ciph = EVP_CIPHER_fetch(NULL, t->sn, NULL);
@@ -259,6 +259,7 @@ int main(void)
259259
ret |= test_block(ciph, name, t->nonce, t->nonce_len,
260260
t->aad, t->aad_len, t->plaintext, t->ptext_len,
261261
t->expected, t->expected_tag, t->key, small);
262+
EVP_CIPHER_free(ciph);
262263
}
263264

264265
if (ret) {

0 commit comments

Comments
 (0)