Fix potential nullptr deref in free_PacketInfo_ptr

This commit is contained in:
Stephen Seo 2023-04-19 19:11:03 +09:00
parent 3fac706d86
commit 211715fc56
2 changed files with 2 additions and 1 deletions

View file

@ -2500,7 +2500,7 @@ void UDPC_free_PacketInfo(UDPC_PacketInfo pInfo) {
} }
void UDPC_free_PacketInfo_ptr(UDPC_PacketInfo *pInfoPtr) { void UDPC_free_PacketInfo_ptr(UDPC_PacketInfo *pInfoPtr) {
if (pInfoPtr->data && pInfoPtr->dataSize > 0) { if (pInfoPtr && pInfoPtr->data && pInfoPtr->dataSize > 0) {
std::free(pInfoPtr->data); std::free(pInfoPtr->data);
pInfoPtr->data = nullptr; pInfoPtr->data = nullptr;
pInfoPtr->dataSize = 0; pInfoPtr->dataSize = 0;

View file

@ -337,4 +337,5 @@ TEST(UDPC, free_packet_ptr) {
UDPC_free_PacketInfo_ptr(&pinfo); UDPC_free_PacketInfo_ptr(&pinfo);
UDPC_free_PacketInfo_ptr(&pinfo); UDPC_free_PacketInfo_ptr(&pinfo);
UDPC_free_PacketInfo_ptr(nullptr);
} }