Skip to content

Commit a56cc03

Browse files
committed
Fix memory management and memory leak
1 parent 75c9ff5 commit a56cc03

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

src/eng_back.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ ENGINE_CTX *ENGINE_CTX_new()
9595
return NULL;
9696
memset(ctx, 0, sizeof(ENGINE_CTX));
9797
ctx->util_ctx = UTIL_CTX_new();
98-
if (!ctx->util_ctx)
98+
if (!ctx->util_ctx) {
99+
OPENSSL_free(ctx);
99100
return NULL;
101+
}
100102
pthread_mutex_init(&ctx->lock, 0);
101103

102104
mod = getenv("PKCS11_MODULE_PATH");

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int UTIL_CTX_ctrl_set_user_interface(UTIL_CTX *ctx, UI_METHOD *ui_method);
5757
int UTIL_CTX_ctrl_set_callback_data(UTIL_CTX *ctx, void *callback_data);
5858
int UTIL_CTX_enumerate_slots(UTIL_CTX *ctx);
5959
int UTIL_CTX_init_libp11(UTIL_CTX *ctx);
60-
int UTIL_CTX_free_libp11(UTIL_CTX *ctx);
60+
void UTIL_CTX_free_libp11(UTIL_CTX *ctx);
6161

6262
void UTIL_CTX_set_vlog_a(UTIL_CTX *ctx, PKCS11_VLOG_A_CB vlog);
6363
void UTIL_CTX_set_debug_level(UTIL_CTX *ctx, int debug_level);

src/util_uri.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int UTIL_CTX_init_libp11(UTIL_CTX *ctx)
145145
if (ctx->pkcs11_ctx && ctx->slot_list)
146146
return 0;
147147

148-
UTIL_CTX_log(ctx, LOG_NOTICE, "PKCS#11: Initializing the engine: %s\n", ctx->module);
148+
UTIL_CTX_log(ctx, LOG_NOTICE, "PKCS#11: Initializing the module: %s\n", ctx->module);
149149

150150
pkcs11_ctx = PKCS11_CTX_new();
151151
PKCS11_set_vlog_a_method(pkcs11_ctx, ctx->vlog);
@@ -164,7 +164,7 @@ int UTIL_CTX_init_libp11(UTIL_CTX *ctx)
164164
return ctx->pkcs11_ctx && ctx->slot_list ? 0 : -1;
165165
}
166166

167-
int UTIL_CTX_free_libp11(UTIL_CTX *ctx)
167+
void UTIL_CTX_free_libp11(UTIL_CTX *ctx)
168168
{
169169
if (ctx->slot_list) {
170170
PKCS11_release_all_slots(ctx->pkcs11_ctx,
@@ -230,7 +230,8 @@ void UTIL_CTX_log(UTIL_CTX *ctx, int level, const char *format, ...)
230230

231231
static char *dump_hex(unsigned char *val, const size_t len)
232232
{
233-
int i, j = 0, size = 2 * len + 1;
233+
int j = 0;
234+
size_t i, size = 2 * len + 1;
234235
char *hexbuf = OPENSSL_malloc((size_t)size);
235236

236237
if (!hexbuf)

0 commit comments

Comments
 (0)