Skip to content

Commit

Permalink
fix memory leaks
Browse files Browse the repository at this point in the history
Signed-off-by: Sergei Ianovich <[email protected]>
  • Loading branch information
Sergei Ianovich authored and yanovich committed Nov 2, 2022
1 parent 228e0b9 commit 7547955
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions gost_eng.c
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ static int gost_engine_finish(ENGINE* e) {
return 1;
}

static void free_NIDs();

static int gost_engine_destroy(ENGINE* e) {
int i;

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

free_cached_groups();
free_NIDs();

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

static void free_NIDs() {
int i;
for (i = 0; i < OSSL_NELEM(missing_NIDs); i++) {
ASN1_OBJECT_free(missing_NIDs[i]->asn1);
}
}

# ifndef BUILDING_GOST_PROVIDER
static
# endif
Expand Down
1 change: 1 addition & 0 deletions gost_lcl.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ struct gost_nid_job {
const char *sn;
const char *ln;
void (*callback)(int nid);
ASN1_OBJECT *asn1;
};

typedef struct gost_nid_job GOST_NID_JOB;
Expand Down
3 changes: 2 additions & 1 deletion test_mgm.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ int main(void)

for (t = testcases; t->sn; t++) {
int small;
const EVP_CIPHER *ciph = EVP_get_cipherbyname(t->sn);
EVP_CIPHER *ciph = (EVP_CIPHER *) EVP_get_cipherbyname(t->sn);
const char *name;
if (!ciph) {
ciph = EVP_CIPHER_fetch(NULL, t->sn, NULL);
Expand All @@ -259,6 +259,7 @@ int main(void)
ret |= test_block(ciph, name, t->nonce, t->nonce_len,
t->aad, t->aad_len, t->plaintext, t->ptext_len,
t->expected, t->expected_tag, t->key, small);
EVP_CIPHER_free(ciph);
}

if (ret) {
Expand Down

0 comments on commit 7547955

Please sign in to comment.