facebook / facebook/infer

False positive: RESOURCE_LEAK lang=C++ simple reproducer with socket and pollfd in method

オープン
#951 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
c++ false-positive
主要言語
OCaml
スター
15.7k
フォーク
2.1k
平均マージ
19時間 36分
マージ済み PR(30日)
13

説明

Hello and thank you for infer,
I ran `infer` on a code base and think it is reporting a false positive, I have narrowed down the code into a simple reproducer which I include below. Thanks.

OS and versions:

```
> uname -a
Linux 4.4.0-87-generic #110-Ubuntu SMP x86_64 x86_64 x86_64 GNU/Linux

> infer --version
Infer version v0.15.0
Copyright 2009 - present Facebook. All Rights Reserved.

> clang++ --version
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
```

Output using the `breaks` `Makefile` target which defines `BREAKS`, note that when `BREAKS` is not defined and the 2 lines from `wait_for_connect()` are inlined - no issues are found.

```
> make clean ; infer run -- make breaks
rm -f my_socket
rm -f my_socket_breaks
Capturing in make/cc mode...
clang++ -DBREAKS=1 -o my_socket_breaks main.cc my_socket.cc
Found 2 source files to analyze in .../infer-out
Starting analysis...

legend:
"F" analyzing a file
"." analyzing a procedure

FF......
Found 1 issue

my_socket.cc:19: error: RESOURCE_LEAK
resource acquired by call to `socket()` at line 17, column 10 is not released after line 19, column 3.
17. m_fd = ::socket(AF_INET, SOCK_STREAM, 0);
18. #if defined BREAKS
19. > wait_for_connect();
20. #else
21. struct pollfd fds[1];

Summary of the reports

RESOURCE_LEAK: 1
```

Source:

```
> cat my_socket.h
namespace MY {

class Socket {
public:
Socket();
~Socket(){};
void connect();

protected:
int m_fd;
private:
void wait_for_connect();
};

}
```

```
>cat my_socket.cc
#include
#include
#include
#include
#include "my_socket.h"

using MY::Socket;

Socket::Socket() : m_fd(-1) {}

void Socket::wait_for_connect() {
struct pollfd fds[1];
fds[0].fd = m_fd;
}

void Socket::connect() {
m_fd = ::socket(AF_INET, SOCK_STREAM, 0);

#if defined BREAKS
wait_for_connect();
#else
struct pollfd fds[1];
fds[0].fd = m_fd;
#endif

::close(m_fd);
}
```

```
> cat Makefile
my_socket: my_socket.cc
clang++ -o my_socket main.cc my_socket.cc

breaks: my_socket.cc
clang++ -DBREAKS=1 -o my_socket_breaks main.cc my_socket.cc

clean:
rm -f my_socket
rm -f my_socket_breaks
```

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。