Skip to content

Commit

Permalink
Remove useless MZ_CUSTOM_ALLOC and MZ_CUSTOM_FREE.
Browse files Browse the repository at this point in the history
It would have required an include to make it useful.
  • Loading branch information
nmoinvaz committed Feb 24, 2023
1 parent ffe3276 commit 261041d
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 137 deletions.
7 changes: 0 additions & 7 deletions mz.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,6 @@
/* MZ_UTILITY */
#define MZ_UNUSED(SYMBOL) ((void)SYMBOL)

#ifndef MZ_CUSTOM_ALLOC
#define MZ_ALLOC(SIZE) (malloc((SIZE)))
#endif
#ifndef MZ_CUSTOM_FREE
#define MZ_FREE(PTR) (free(PTR))
#endif

#if defined(_WIN32) && defined(MZ_EXPORTS)
#define MZ_EXPORT __declspec(dllexport)
#else
Expand Down
12 changes: 6 additions & 6 deletions mz_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ static int32_t mz_stream_ioapi_set_filefunc64(void *stream, zlib_filefunc64_def
static void *mz_stream_ioapi_create(void **stream) {
mz_stream_ioapi *ioapi = NULL;

ioapi = (mz_stream_ioapi *)MZ_ALLOC(sizeof(mz_stream_ioapi));
ioapi = (mz_stream_ioapi *)malloc(sizeof(mz_stream_ioapi));
if (ioapi) {
memset(ioapi, 0, sizeof(mz_stream_ioapi));
ioapi->stream.vtbl = &mz_stream_ioapi_vtbl;
Expand All @@ -253,7 +253,7 @@ static void mz_stream_ioapi_delete(void **stream) {
return;
ioapi = (mz_stream_ioapi *)*stream;
if (ioapi)
MZ_FREE(ioapi);
free(ioapi);
*stream = NULL;
}

Expand Down Expand Up @@ -418,7 +418,7 @@ zipFile zipOpen_MZ(void *stream, int append, const char **globalcomment) {
if (globalcomment)
mz_zip_get_comment(handle, globalcomment);

compat = (mz_compat *)MZ_ALLOC(sizeof(mz_compat));
compat = (mz_compat *)malloc(sizeof(mz_compat));
if (compat) {
compat->handle = handle;
compat->stream = stream;
Expand Down Expand Up @@ -628,7 +628,7 @@ int zipClose2_64(zipFile file, const char *global_comment, uint16_t version_made
mz_stream_delete(&compat->stream);
}

MZ_FREE(compat);
free(compat);

return err;
}
Expand Down Expand Up @@ -763,7 +763,7 @@ unzFile unzOpen_MZ(void *stream) {
return NULL;
}

compat = (mz_compat *)MZ_ALLOC(sizeof(mz_compat));
compat = (mz_compat *)malloc(sizeof(mz_compat));
if (compat) {
compat->handle = handle;
compat->stream = stream;
Expand Down Expand Up @@ -791,7 +791,7 @@ int unzClose(unzFile file) {
mz_stream_delete(&compat->stream);
}

MZ_FREE(compat);
free(compat);

return err;
}
Expand Down
14 changes: 7 additions & 7 deletions mz_crypt_apple.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm) {
void *mz_crypt_sha_create(void **handle) {
mz_crypt_sha *sha = NULL;

sha = (mz_crypt_sha *)MZ_ALLOC(sizeof(mz_crypt_sha));
sha = (mz_crypt_sha *)malloc(sizeof(mz_crypt_sha));
if (sha) {
memset(sha, 0, sizeof(mz_crypt_sha));
sha->algorithm = MZ_HASH_SHA256;
Expand All @@ -178,7 +178,7 @@ void mz_crypt_sha_delete(void **handle) {
sha = (mz_crypt_sha *)*handle;
if (sha) {
mz_crypt_sha_reset(*handle);
MZ_FREE(sha);
free(sha);
}
*handle = NULL;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ void mz_crypt_aes_set_mode(void *handle, int32_t mode) {
void *mz_crypt_aes_create(void **handle) {
mz_crypt_aes *aes = NULL;

aes = (mz_crypt_aes *)MZ_ALLOC(sizeof(mz_crypt_aes));
aes = (mz_crypt_aes *)malloc(sizeof(mz_crypt_aes));
if (aes)
memset(aes, 0, sizeof(mz_crypt_aes));
if (handle)
Expand All @@ -293,7 +293,7 @@ void mz_crypt_aes_delete(void **handle) {
aes = (mz_crypt_aes *)*handle;
if (aes) {
mz_crypt_aes_reset(*handle);
MZ_FREE(aes);
free(aes);
}
*handle = NULL;
}
Expand Down Expand Up @@ -388,7 +388,7 @@ int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle) {
void *mz_crypt_hmac_create(void **handle) {
mz_crypt_hmac *hmac = NULL;

hmac = (mz_crypt_hmac *)MZ_ALLOC(sizeof(mz_crypt_hmac));
hmac = (mz_crypt_hmac *)malloc(sizeof(mz_crypt_hmac));
if (hmac) {
memset(hmac, 0, sizeof(mz_crypt_hmac));
hmac->algorithm = MZ_HASH_SHA256;
Expand All @@ -406,7 +406,7 @@ void mz_crypt_hmac_delete(void **handle) {
hmac = (mz_crypt_hmac *)*handle;
if (hmac) {
mz_crypt_hmac_free(*handle);
MZ_FREE(hmac);
free(hmac);
}
*handle = NULL;
}
Expand Down Expand Up @@ -454,7 +454,7 @@ int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data

if (status == errSecSuccess) {
*signature_size = CFDataGetLength(signature_out);
*signature = (uint8_t *)MZ_ALLOC(*signature_size);
*signature = (uint8_t *)malloc(*signature_size);

memcpy(*signature, CFDataGetBytePtr(signature_out), *signature_size);

Expand Down
16 changes: 8 additions & 8 deletions mz_crypt_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm) {
void *mz_crypt_sha_create(void **handle) {
mz_crypt_sha *sha = NULL;

sha = (mz_crypt_sha *)MZ_ALLOC(sizeof(mz_crypt_sha));
sha = (mz_crypt_sha *)malloc(sizeof(mz_crypt_sha));
if (sha) {
memset(sha, 0, sizeof(mz_crypt_sha));
sha->algorithm = MZ_HASH_SHA256;
Expand All @@ -219,7 +219,7 @@ void mz_crypt_sha_delete(void **handle) {
sha = (mz_crypt_sha *)*handle;
if (sha) {
mz_crypt_sha_reset(*handle);
MZ_FREE(sha);
free(sha);
}
*handle = NULL;
}
Expand Down Expand Up @@ -315,7 +315,7 @@ void mz_crypt_aes_set_mode(void *handle, int32_t mode) {
void *mz_crypt_aes_create(void **handle) {
mz_crypt_aes *aes = NULL;

aes = (mz_crypt_aes *)MZ_ALLOC(sizeof(mz_crypt_aes));
aes = (mz_crypt_aes *)malloc(sizeof(mz_crypt_aes));
if (aes)
memset(aes, 0, sizeof(mz_crypt_aes));
if (handle)
Expand All @@ -330,7 +330,7 @@ void mz_crypt_aes_delete(void **handle) {
return;
aes = (mz_crypt_aes *)*handle;
if (aes)
MZ_FREE(aes);
free(aes);
*handle = NULL;
}

Expand Down Expand Up @@ -472,7 +472,7 @@ int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle) {
void *mz_crypt_hmac_create(void **handle) {
mz_crypt_hmac *hmac = NULL;

hmac = (mz_crypt_hmac *)MZ_ALLOC(sizeof(mz_crypt_hmac));
hmac = (mz_crypt_hmac *)malloc(sizeof(mz_crypt_hmac));
if (hmac) {
memset(hmac, 0, sizeof(mz_crypt_hmac));
hmac->algorithm = MZ_HASH_SHA256;
Expand All @@ -490,7 +490,7 @@ void mz_crypt_hmac_delete(void **handle) {
hmac = (mz_crypt_hmac *)*handle;
if (hmac) {
mz_crypt_hmac_reset(*handle);
MZ_FREE(hmac);
free(hmac);
}
*handle = NULL;
}
Expand Down Expand Up @@ -545,7 +545,7 @@ int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data
BIO_get_mem_ptr(signature_bio, &buf_mem);

*signature_size = buf_mem->length;
*signature = MZ_ALLOC(buf_mem->length);
*signature = malloc(buf_mem->length);

memcpy(*signature, buf_mem->data, buf_mem->length);
}
Expand Down Expand Up @@ -573,7 +573,7 @@ int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data
PKCS12_free(p12);

if (err != MZ_OK && *signature) {
MZ_FREE(*signature);
free(*signature);
*signature = NULL;
*signature_size = 0;
}
Expand Down
34 changes: 17 additions & 17 deletions mz_crypt_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ typedef struct mz_crypt_sha_s {
void mz_crypt_sha_reset(void *handle) {
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
if (sha->algorithm == MZ_HASH_SHA224) {
MZ_FREE(sha->sha224);
free(sha->sha224);
sha->sha224 = NULL;
} else {
if (sha->hash)
Expand All @@ -213,7 +213,7 @@ int32_t mz_crypt_sha_begin(void *handle) {
return MZ_PARAM_ERROR;

if (sha->algorithm == MZ_HASH_SHA224) {
sha->sha224 = MZ_ALLOC(sizeof(mz_crypt_sha224));
sha->sha224 = malloc(sizeof(mz_crypt_sha224));
if (!sha->sha224)
return MZ_MEM_ERROR;
mz_crypt_sha224_init(sha->sha224);
Expand Down Expand Up @@ -316,7 +316,7 @@ void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm) {
void *mz_crypt_sha_create(void **handle) {
mz_crypt_sha *sha = NULL;

sha = (mz_crypt_sha *)MZ_ALLOC(sizeof(mz_crypt_sha));
sha = (mz_crypt_sha *)malloc(sizeof(mz_crypt_sha));
if (sha) {
memset(sha, 0, sizeof(mz_crypt_sha));
sha->algorithm = MZ_HASH_SHA256;
Expand All @@ -334,7 +334,7 @@ void mz_crypt_sha_delete(void **handle) {
sha = (mz_crypt_sha *)*handle;
if (sha) {
mz_crypt_sha_reset(*handle);
MZ_FREE(sha);
free(sha);
}
*handle = NULL;
}
Expand Down Expand Up @@ -427,7 +427,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l
result = CryptAcquireContext(&aes->provider, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_SILENT);
if (result) {
key_blob_size = sizeof(key_blob_header_s) + key_length;
key_blob = (uint8_t *)MZ_ALLOC(key_blob_size);
key_blob = (uint8_t *)malloc(key_blob_size);
if (key_blob) {
key_blob_s = (key_blob_header_s *)key_blob;
key_blob_s->hdr.bType = PLAINTEXTKEYBLOB;
Expand All @@ -441,7 +441,7 @@ static int32_t mz_crypt_aes_set_key(void *handle, const void *key, int32_t key_l
result = CryptImportKey(aes->provider, key_blob, key_blob_size, 0, 0, &aes->key);

SecureZeroMemory(key_blob, key_blob_size);
MZ_FREE(key_blob);
free(key_blob);
} else {
err = MZ_MEM_ERROR;
}
Expand Down Expand Up @@ -477,7 +477,7 @@ void mz_crypt_aes_set_mode(void *handle, int32_t mode) {
void *mz_crypt_aes_create(void **handle) {
mz_crypt_aes *aes = NULL;

aes = (mz_crypt_aes *)MZ_ALLOC(sizeof(mz_crypt_aes));
aes = (mz_crypt_aes *)malloc(sizeof(mz_crypt_aes));
if (aes)
memset(aes, 0, sizeof(mz_crypt_aes));
if (handle)
Expand All @@ -493,7 +493,7 @@ void mz_crypt_aes_delete(void **handle) {
aes = (mz_crypt_aes *)*handle;
if (aes) {
mz_crypt_aes_free(*handle);
MZ_FREE(aes);
free(aes);
}
*handle = NULL;
}
Expand Down Expand Up @@ -567,7 +567,7 @@ int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
if (pad_key_length % 2 == 1)
pad_key_length += 1;
key_blob_size = sizeof(key_blob_header_s) + pad_key_length;
key_blob = (uint8_t *)MZ_ALLOC(key_blob_size);
key_blob = (uint8_t *)malloc(key_blob_size);
}

if (key_blob) {
Expand All @@ -588,7 +588,7 @@ int32_t mz_crypt_hmac_init(void *handle, const void *key, int32_t key_length) {
result = CryptSetHashParam(hmac->hash, HP_HMAC_INFO, (uint8_t *)&hmac->info, 0);

SecureZeroMemory(key_blob, key_blob_size);
MZ_FREE(key_blob);
free(key_blob);
} else if (err == MZ_OK) {
err = MZ_MEM_ERROR;
}
Expand Down Expand Up @@ -667,7 +667,7 @@ int32_t mz_crypt_hmac_copy(void *src_handle, void *target_handle) {
void *mz_crypt_hmac_create(void **handle) {
mz_crypt_hmac *hmac = NULL;

hmac = (mz_crypt_hmac *)MZ_ALLOC(sizeof(mz_crypt_hmac));
hmac = (mz_crypt_hmac *)malloc(sizeof(mz_crypt_hmac));
if (hmac) {
memset(hmac, 0, sizeof(mz_crypt_hmac));
hmac->algorithm = MZ_HASH_SHA256;
Expand All @@ -685,7 +685,7 @@ void mz_crypt_hmac_delete(void **handle) {
hmac = (mz_crypt_hmac *)*handle;
if (hmac) {
mz_crypt_hmac_free(*handle);
MZ_FREE(hmac);
free(hmac);
}
*handle = NULL;
}
Expand Down Expand Up @@ -785,7 +785,7 @@ int32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data
NULL, (DWORD *)signature_size);

if (result && *signature_size > 0)
*signature = (uint8_t *)MZ_ALLOC(*signature_size);
*signature = (uint8_t *)malloc(*signature_size);

if (result && *signature)
result = CryptSignMessage(&sign_params, FALSE, 1, (const BYTE **)messages, (DWORD *)messages_sizes,
Expand Down Expand Up @@ -825,7 +825,7 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
NULL, (DWORD *)&decoded_size, NULL);

if (result && decoded_size > 0)
decoded = (uint8_t *)MZ_ALLOC(decoded_size);
decoded = (uint8_t *)malloc(decoded_size);

if (result && decoded)
result = CryptVerifyMessageSignature(&verify_params, 0, signature, signature_size,
Expand Down Expand Up @@ -868,7 +868,7 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
CryptMsgGetParam(crypt_msg, CMSG_SIGNER_UNAUTH_ATTR_PARAM, 0, NULL, &ts_signature_size);

if (result && ts_signature_size > 0)
ts_signature = (uint8_t *)MZ_ALLOC(ts_signature_size);
ts_signature = (uint8_t *)malloc(ts_signature_size);

if (result && ts_signature) {
result = CryptMsgGetParam(crypt_msg, CMSG_SIGNER_UNAUTH_ATTR_PARAM, 0, ts_signature,
Expand All @@ -893,7 +893,7 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
}

if (ts_signature)
MZ_FREE(ts_signature);
free(ts_signature);

if (crypt_context)
CryptMemFree(crypt_context);
Expand All @@ -916,7 +916,7 @@ int32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *si
CryptMsgClose(crypt_msg);

if (decoded)
MZ_FREE(decoded);
free(decoded);

return err;
}
Expand Down
Loading

0 comments on commit 261041d

Please sign in to comment.