Skip to content

Commit 9d2951b

Browse files
committed
Fix for memory leak
1 parent e153afd commit 9d2951b

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/internal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,8 @@ int IdentifyAsn1Key(const byte* in, word32 inSz, int isPrivate, void* heap,
13381338
ret = key->keySigId;
13391339
}
13401340

1341-
if (pkey == NULL || ret == WS_UNIMPLEMENTED_E) {
1341+
/* if not returning key then free it */
1342+
if (pkey == NULL || *pkey == NULL) {
13421343
wolfSSH_KEY_clean(key);
13431344
WFREE(key, heap, dynType);
13441345
key = NULL;

src/ssh.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ static int DoAsn1Key(const byte* in, word32 inSz, byte** out,
17511751
c32toa((word32)WSTRLEN(keyFormat), &newKey[idx]);
17521752
idx += LENGTH_SZ;
17531753
WMEMCPY(&newKey[idx], keyFormat, (word32)WSTRLEN(keyFormat));
1754-
idx += WSTRLEN(keyFormat);
1754+
idx += (word32)WSTRLEN(keyFormat);
17551755

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

17971797
wolfSSH_KEY_clean(key);
1798+
WFREE(key, heap, isPrivate ? DYNTYPE_PRIVKEY : DYNTYPE_PUBKEY);
1799+
17981800
if (*out == NULL) {
17991801
WFREE(newKey, heap, DYNTYPE_PRIVKEY);
18001802
}

0 commit comments

Comments
 (0)