llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

False positive for potentially memory leak after transferring ownership to C array storage of > 1 dimension

Open llvmbot opened this issue 12 years ago • 5 comments

Bugzilla Link 18966
Version 3.3
OS MacOS X
Attachments Self contained .m file
Reporter LLVM Bugzilla Contributor
CC @belkadan

Extended Description

When retained objects are assigned into a C array of greater than 1 dimension in a longer lived scope, the objects a potential leak is reported. I have tried this with a static global 2d array and an instance ivar. Attached test case contains both flavors.

Note that the same error does not occur with a 1d array.

llvmbot avatar Feb 25 '14 21:02 llvmbot

Cloned to rdar://problem/16173744

belkadan avatar Feb 26 '14 19:02 belkadan

More data: if the second index is replaced by a constant, or the first index is replaced by 0, the warning goes away.

My guess is that the analyzer is just unable to represent the location "foo[x][y]", because it's "&foo + x * sizeof(foo[0]) + y".

belkadan avatar Feb 26 '14 19:02 belkadan

assigned to @tkremenek

llvmbot avatar Feb 25 '14 21:02 llvmbot

Bisected: the reported behavior no longer reproduces starting with #133381 (https://github.com/llvm/llvm-project/commit/d63cc4c87689a79d25521c9aa2ce4a335e5984e3).

Godbolt: https://godbolt.org/z/sTE85Eobo

  • Clang 20.1.0: Reports potential leaks at lines 28 and 34
  • Clang 21.1.0: No longer reports potential leaks
  • Clang (trunk): Completes without analyzer diagnostics

This is only an observed change in behavior. I have not checked whether #133381 addresses the cause of this report or only stops it from reproducing; whether that resolves the issue is up to the maintainers.

Prepared with assistance from Codex.

hongtaihu avatar Nov 01 '26 09:11 hongtaihu

https://github.com/llvm/llvm-project/pull/133381 fixes this issue, but none of the test cases in https://github.com/llvm/llvm-project/pull/133381 cover the repro in this issue.

benedekaibas avatar Nov 10 '26 13:11 benedekaibas