Skip to content

Commit 5a6d100

Browse files
authored
Fix leaking EVP_MAC_CTX in one shot
1 parent cf8cbe9 commit 5a6d100

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/native/libs/System.Security.Cryptography.Native/pal_evp_mac.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,32 +369,35 @@ int32_t CryptoNative_EvpMacOneShot(EVP_MAC* mac,
369369

370370
params[i] = OSSL_PARAM_construct_end();
371371

372+
int32_t ret = 0;
373+
372374
if (!EVP_MAC_init(ctx, NULL, 0, params))
373375
{
374-
EVP_MAC_CTX_free(ctx);
375-
return 0;
376+
goto done;
376377
}
377378

378379
if (!EVP_MAC_update(ctx, data, dataLengthT))
379380
{
380-
EVP_MAC_CTX_free(ctx);
381-
return 0;
381+
goto done;
382382
}
383383

384384
size_t written = 0;
385385

386386
if (!EVP_MAC_final(ctx, destination, &written, macLengthT))
387387
{
388-
EVP_MAC_CTX_free(ctx);
389-
return 0;
388+
goto done;
390389
}
391390

392391
if (written != macLengthT)
393392
{
394-
return -3;
393+
ret = -3;
394+
goto done;
395395
}
396396

397-
return 1;
397+
ret = 1;
398+
done:
399+
EVP_MAC_CTX_free(ctx);
400+
return ret;
398401
}
399402
#else
400403
(void)mac;

0 commit comments

Comments
 (0)