crypt32: If a decoding function failed, free the memory allocated for it.

This commit is contained in:
Juan Lang 2007-11-08 08:55:36 -08:00 committed by Alexandre Julliard
parent 4c981e20ef
commit 2e4242b545
1 changed files with 12 additions and 0 deletions

View File

@ -231,6 +231,14 @@ static BOOL CRYPT_DecodeEnsureSpace(DWORD dwFlags,
return ret;
}
static void CRYPT_FreeSpace(PCRYPT_DECODE_PARA pDecodePara, LPVOID pv)
{
if (pDecodePara && pDecodePara->pfnFree)
pDecodePara->pfnFree(pv);
else
LocalFree(pv);
}
/* Helper function to check *pcbStructInfo and set it to the required size.
* Assumes pvStructInfo is not NULL.
*/
@ -540,6 +548,8 @@ static BOOL CRYPT_AsnDecodeSequence(struct AsnDecodeSequenceItem items[],
ret = CRYPT_AsnDecodeSequenceItems(items, cItem,
ptr, dataLen, dwFlags, pvStructInfo, nextData,
&cbDecoded);
if (!ret && (dwFlags & CRYPT_DECODE_ALLOC_FLAG))
CRYPT_FreeSpace(pDecodePara, pvStructInfo);
}
}
}
@ -727,6 +737,8 @@ static BOOL CRYPT_AsnDecodeArray(const struct AsnArrayDescriptor *arrayDesc,
ptr += itemDecoded;
}
}
if (!ret && (dwFlags & CRYPT_DECODE_ALLOC_FLAG))
CRYPT_FreeSpace(pDecodePara, pvStructInfo);
}
}
if (itemSizes != &itemSize)