Skip to content

Commit

Permalink
Safety changes after malloc to CHIPMem conversions (#3230)
Browse files Browse the repository at this point in the history
#### Problem

As part of heap memory management, a recent change (#3143) replaced
malloc()-family calls one-for-one with their "CHIPMem.h" equivalents.
Reviewers proposed some related small safety changes.

 #### Summary of Changes

- added an assert()
- null out two dead pointers
  • Loading branch information
kpschoedel authored Oct 14, 2020
1 parent 90090c6 commit 5b0142e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/inet/tests/TestInetCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ void InitNetwork()
{
uint64_t iid = gNetworkOptions.LocalIPv6Addr[j].InterfaceId();
char * tap_name = (char *) chip::Platform::MemoryAlloc(sizeof(gDefaultTapDeviceName));
assert(tap_name);
snprintf(tap_name, sizeof(gDefaultTapDeviceName), "chip-dev-%" PRIx64, iid & 0xFFFF);
tap_name[sizeof(gDefaultTapDeviceName) - 1] = 0;
gNetworkOptions.TapDeviceName.push_back(tap_name);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/core/CHIPTLVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@ CHIP_ERROR TLVReader::DupBytes(uint8_t *& buf, uint32_t & dataLen)
if (err != CHIP_NO_ERROR)
{
chip::Platform::MemoryFree(buf);
buf = nullptr;
return err;
}

Expand Down Expand Up @@ -739,6 +740,7 @@ CHIP_ERROR TLVReader::DupString(char *& buf)
if (err != CHIP_NO_ERROR)
{
chip::Platform::MemoryFree(buf);
buf = nullptr;
return err;
}

Expand Down

0 comments on commit 5b0142e

Please sign in to comment.