From 72888da82b25fd6507bcd75b4d89e8bccba80439 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Thu, 30 Nov 2023 14:35:04 -0800 Subject: [PATCH] Unused Heap 1. Moved the heap variable declaration to the top of the function ChannelUpdateForward(). 2. Only set heap if channel is non-null. 3. Tag heap as unused. Depending on the build environment, it might be left out by the preprocessor. 4. Fix a bad memory type name used in a malloc in the agent. 5. Fix a use of heap when ctx->heap was intended. 6. Fix a typo where ssh->ctx->heap was intended. --- src/agent.c | 2 +- src/internal.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/agent.c b/src/agent.c index 9706706f0..f72b7185e 100644 --- a/src/agent.c +++ b/src/agent.c @@ -1553,7 +1553,7 @@ void wolfSSH_AGENT_ID_free(WOLFSSH_AGENT_ID* id, void* heap) WFREE(id->keyBuffer, heap, DYNTYPE_STRING); } WMEMSET(id, 0, sizeof(WOLFSSH_AGENT_ID)); - WFREE(id, heap, DYNATYPE_AGENT_ID); + WFREE(id, heap, DYNTYPE_AGENT_ID); } WLOG(WS_LOG_AGENT, "Leaving wolfSSH_AGENT_ID_free()"); diff --git a/src/internal.c b/src/internal.c index 2b722f7d8..ccad259d4 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1516,7 +1516,7 @@ static int SetHostCertificate(WOLFSSH_CTX* ctx, if (pvtKey->publicKeyFmt == certId) { if (pvtKey->cert != NULL) { - WFREE(pvtKey->cert, heap, dynamicType); + WFREE(pvtKey->cert, ctx->heap, dynamicType); } } else { @@ -2210,17 +2210,19 @@ int ChannelUpdateForward(WOLFSSH_CHANNEL* channel, const char* origin, word32 originPort, int isDirect) { + void* heap = NULL; int ret = WS_SUCCESS; char* hostCopy = NULL; char* originCopy = NULL; word32 hostSz; word32 originSz; + WOLFSSH_UNUSED(heap); + if (channel == NULL || host == NULL || origin == NULL) ret = WS_BAD_ARGUMENT; else { - void* heap = channel->ssh->ctx->heap; - + heap = channel->ssh->ctx->heap; hostSz = (word32)WSTRLEN(host) + 1; originSz = (word32)WSTRLEN(origin) + 1; hostCopy = (char*)WMALLOC(hostSz, heap, DYNTYPE_STRING); @@ -5614,7 +5616,7 @@ static int DoUserAuthRequestRsa(WOLFSSH* ssh, WS_UserAuthData_PublicKey* pk, if (checkDigest) WFREE(checkDigest, ssh->ctx->heap, DYNTYPE_BUFFER); if (encDigest) - WFREE(encDigest, ssh->ctx_heap, DYNTYPE_BUFFER); + WFREE(encDigest, ssh->ctx->heap, DYNTYPE_BUFFER); #endif WLOG(WS_LOG_DEBUG, "Leaving DoUserAuthRequestRsa(), ret = %d", ret); return ret;