Skip to content

Commit

Permalink
Fix for memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
aidangarske committed Dec 18, 2024
1 parent e153afd commit 9d2951b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,8 @@ int IdentifyAsn1Key(const byte* in, word32 inSz, int isPrivate, void* heap,
ret = key->keySigId;
}

if (pkey == NULL || ret == WS_UNIMPLEMENTED_E) {
/* if not returning key then free it */
if (pkey == NULL || *pkey == NULL) {
wolfSSH_KEY_clean(key);
WFREE(key, heap, dynType);
key = NULL;
Expand Down
4 changes: 3 additions & 1 deletion src/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ static int DoAsn1Key(const byte* in, word32 inSz, byte** out,
c32toa((word32)WSTRLEN(keyFormat), &newKey[idx]);
idx += LENGTH_SZ;
WMEMCPY(&newKey[idx], keyFormat, (word32)WSTRLEN(keyFormat));
idx += WSTRLEN(keyFormat);
idx += (word32)WSTRLEN(keyFormat);

/* encode public exponent (e) */
c32toa(eSz, &newKey[idx]);
Expand Down Expand Up @@ -1795,6 +1795,8 @@ static int DoAsn1Key(const byte* in, word32 inSz, byte** out,
}

wolfSSH_KEY_clean(key);
WFREE(key, heap, isPrivate ? DYNTYPE_PRIVKEY : DYNTYPE_PUBKEY);

if (*out == NULL) {
WFREE(newKey, heap, DYNTYPE_PRIVKEY);
}
Expand Down

0 comments on commit 9d2951b

Please sign in to comment.