Skip to content

Commit

Permalink
Enable more clang tidy checks, fix a memory leak found by tidy (#17646)
Browse files Browse the repository at this point in the history
* Enable more clang tidy checks, fix a memory leak found by tidy

* bzero check seems to also be ok

* make darwin usage of bzero when clearing fd sets be ok

* Also fix TestSystemWakeEvent
  • Loading branch information
andy31415 authored and pull[bot] committed Aug 22, 2023
1 parent 25a4d2b commit 1014888
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ Checks: >
-clang-analyzer-security.insecureAPI.strcpy,
-clang-analyzer-nullability.NullablePassedToNonnull,
-clang-analyzer-optin.performance.Padding,
-clang-analyzer-security.insecureAPI.bzero,
-clang-analyzer-unix.cstring.NullArg,
-clang-analyzer-security.insecureAPI.rand,
-clang-analyzer-core.NonNullParamChecker,
-clang-analyzer-nullability.NullPassedToNonnull,
-clang-analyzer-unix.Malloc,
-clang-analyzer-valist.Unterminated,
-clang-analyzer-cplusplus.NewDeleteLeaks,
-clang-diagnostic-implicit-int-conversion
WarningsAsErrors: '*'
HeaderFilterRegex: '(src|examples|zzz_generated|credentials).*(?<!third_party.*repo)'
3 changes: 3 additions & 0 deletions src/platform/Linux/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,10 @@ void ThreadStackManagerImpl::_OnNetworkScanFinished(GAsyncResult * res)
std::unique_ptr<GVariantIter, GVariantIterDeleter> iter;
g_variant_get(scan_result.get(), "a(tstayqqyyyybb)", &MakeUniquePointerReceiver(iter).Get());
if (!iter)
{
delete scanResult;
return;
}

guint64 ext_address;
const gchar * network_name;
Expand Down
6 changes: 6 additions & 0 deletions src/system/SystemLayerImplSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,15 @@ void LayerImplSelect::PrepareEvents()
Clock::ToTimeval(sleepTime, mNextTimeout);

mMaxFd = -1;

// NOLINTBEGIN(clang-analyzer-security.insecureAPI.bzero)
//
// NOTE: darwin uses bzero to clear out FD sets. This is not a security concern.
FD_ZERO(&mSelected.mReadSet);
FD_ZERO(&mSelected.mWriteSet);
FD_ZERO(&mSelected.mErrorSet);
// NOLINTEND(clang-analyzer-security.insecureAPI.bzero)

for (auto & w : mSocketWatchPool)
{
if (w.mFD != kInvalidFd)
Expand Down
5 changes: 5 additions & 0 deletions src/system/tests/TestSystemWakeEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ struct TestContext

int SelectWakeEvent(timeval timeout = {})
{
// NOLINTBEGIN(clang-analyzer-security.insecureAPI.bzero)
//
// NOTE: darwin uses bzero to clear out FD sets. This is not a security concern.
FD_ZERO(&mReadSet);
FD_ZERO(&mWriteSet);
FD_ZERO(&mErrorSet);
// NOLINTEND(clang-analyzer-security.insecureAPI.bzero)

FD_SET(WakeEventTest::GetReadFD(mWakeEvent), &mReadSet);
return select(WakeEventTest::GetReadFD(mWakeEvent) + 1, &mReadSet, &mWriteSet, &mErrorSet, &timeout);
}
Expand Down

0 comments on commit 1014888

Please sign in to comment.