mirror of
https://github.com/zlib-ng/minizip-ng
synced 2025-03-28 21:13:18 +00:00
More clean up memory freeing in mz_crypt classes.
This commit is contained in:
parent
67010ceaca
commit
762333d6e9
@ -562,7 +562,7 @@ static void HMAC_CTX_free(HMAC_CTX *ctx) {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_crypt_hmac_reset(void *handle) {
|
||||
static void mz_crypt_hmac_free(void *handle) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER < 0x30000000L
|
||||
@ -575,9 +575,15 @@ void mz_crypt_hmac_reset(void *handle) {
|
||||
#endif
|
||||
|
||||
hmac->ctx = NULL;
|
||||
hmac->error = 0;
|
||||
}
|
||||
|
||||
void mz_crypt_hmac_reset(void *handle) {
|
||||
mz_crypt_hmac *hmac = (mz_crypt_hmac *)handle;
|
||||
|
||||
mz_crypt_init();
|
||||
mz_crypt_hmac_free(handle);
|
||||
|
||||
hmac->error = 0;
|
||||
}
|
||||
|
||||
int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
|
||||
|
@ -58,16 +58,21 @@ typedef struct mz_crypt_sha_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_crypt_sha_reset(void *handle) {
|
||||
static void mz_crypt_sha_free(void *handle) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
if (sha->hash)
|
||||
BCryptDestroyHash(sha->hash);
|
||||
sha->hash = NULL;
|
||||
if (sha->provider)
|
||||
BCryptCloseAlgorithmProvider(sha->provider, 0);
|
||||
free(sha->buffer);
|
||||
sha->hash = NULL;
|
||||
sha->provider = NULL;
|
||||
free(sha->buffer);
|
||||
sha->buffer = NULL;
|
||||
}
|
||||
|
||||
void mz_crypt_sha_reset(void *handle) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
mz_crypt_sha_free(handle);
|
||||
sha->error = 0;
|
||||
}
|
||||
|
||||
@ -99,7 +104,7 @@ int32_t mz_crypt_sha_begin(void *handle) {
|
||||
|
||||
status = BCryptOpenAlgorithmProvider(&sha->provider, alg_id, NULL, 0);
|
||||
if (NT_SUCCESS(status)) {
|
||||
status = BCryptGetProperty(sha->provider, BCRYPT_OBJECT_LENGTH, (PUCHAR)&buffer_size, result_size,
|
||||
status = BCryptGetProperty(sha->provider, BCRYPT_OBJECT_LENGTH, (PUCHAR)&buffer_size, result_size,
|
||||
&result_size, 0);
|
||||
}
|
||||
if (NT_SUCCESS(status)) {
|
||||
@ -186,7 +191,7 @@ void mz_crypt_sha_delete(void **handle) {
|
||||
return;
|
||||
sha = (mz_crypt_sha *)*handle;
|
||||
if (sha) {
|
||||
mz_crypt_sha_reset(*handle);
|
||||
mz_crypt_sha_free(*handle);
|
||||
free(sha);
|
||||
}
|
||||
*handle = NULL;
|
||||
|
@ -49,7 +49,7 @@ typedef struct mz_crypt_sha_s {
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_crypt_sha_reset(void *handle) {
|
||||
static void mz_crypt_sha_free(void *handle) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
if (sha->hash)
|
||||
CryptDestroyHash(sha->hash);
|
||||
@ -57,6 +57,11 @@ void mz_crypt_sha_reset(void *handle) {
|
||||
if (sha->provider)
|
||||
CryptReleaseContext(sha->provider, 0);
|
||||
sha->provider = 0;
|
||||
}
|
||||
|
||||
void mz_crypt_sha_reset(void *handle) {
|
||||
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
|
||||
mz_crypt_sha_free(handle);
|
||||
sha->error = 0;
|
||||
}
|
||||
|
||||
@ -182,7 +187,7 @@ void mz_crypt_sha_delete(void **handle) {
|
||||
return;
|
||||
sha = (mz_crypt_sha *)*handle;
|
||||
if (sha) {
|
||||
mz_crypt_sha_reset(*handle);
|
||||
mz_crypt_sha_free(*handle);
|
||||
free(sha);
|
||||
}
|
||||
*handle = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user