github / github/codeql

C: Question aboutDataFlow Analyse

未關閉
#10,534 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
question
主要語言
CodeQL
星號
10.1k
分支
2.1k
平均合併
2 天 15 小時
30 天內合併 PR
141

描述

Hi, I learn how to write ql to do dataflow analyse, and then I want to detect memory leak like missing `free` after `malloc`. But I met a problem, I don't know how to solve this problem.
C demo:
```
char* gen_ptr(void)
{
char* a = malloc(1);
return a;
}
int main(void)
{
char* a;
a = gen_ptr();
a = gen_ptr();
free(a);
return 0;
}
```
In this code, `gen_ptr` is called twice, but only freed in the end, there is a memory leak because the first `a `is not freed.
I use dataflow analyse and want to detect `malloc` in the first `gen_ptr` doesn't have a free as sink. But I faild....because `malloc` in `gen_ptr `does have a sink in the second one!!!
I think for a long time but do not know how to solve this problem :(

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。