Skip to content

Commit

Permalink
Fix potential memory leak (#7245)
Browse files Browse the repository at this point in the history
Summary:
```
int* value = new int;
ASSERT_NE(nullptr, value);
```
`ASSERT_NE` can expand the expression such that a memory leak is
reported by clang analyzer.
We can remove this ASSERT_NE since we can assume the memory allocation
must succeed. Otherwise a bad alloc exception will be thrown and the
process will be killed anyway.

Test plan (dev server):
```
USE_CLANG=1 make analyze
```

Pull Request resolved: #7245

Reviewed By: jay-zhuang

Differential Revision: D23079641

Pulled By: riversand963

fbshipit-source-id: a6739a903f90f8715f6f1ef3e5c8a329245b8e78
  • Loading branch information
riversand963 authored and facebook-github-bot committed Aug 12, 2020
1 parent 378bc94 commit 76609cd
Showing 1 changed file with 0 additions and 2 deletions.
2 changes: 0 additions & 2 deletions util/timer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ TEST_F(TimerTest, CancelRunningTask) {
Timer timer(mock_env_.get());
ASSERT_TRUE(timer.Start());
int* value = new int;
ASSERT_NE(nullptr, value); // make linter happy
*value = 0;
SyncPoint::GetInstance()->DisableProcessing();
SyncPoint::GetInstance()->LoadDependency({
Expand Down Expand Up @@ -337,7 +336,6 @@ TEST_F(TimerTest, ShutdownRunningTask) {
ASSERT_TRUE(timer.Start());

int* value = new int;
ASSERT_NE(nullptr, value);
*value = 0;
timer.Add(
[&]() {
Expand Down

0 comments on commit 76609cd

Please sign in to comment.