File: SwigMemoryLeak.md

package info (click to toggle)
error-prone-java 2.18.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 23,204 kB
  • sloc: java: 222,992; xml: 1,319; sh: 25; makefile: 7
file content (13 lines) | stat: -rw-r--r-- 935 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
SWIG is a tool that will automatically generate Java bindings to C++ code. It is
possible to %ignore in SWIG a C++ object's destructor, this is trivially
achieved when using %ignoreall and then selectively %unignore-ing an API. SWIG
cleans up C++ objects using a delete method, which is most commonly called by a
finalizer. When a SWIG generated delete method can't call a destructor, as it is
hidden, the delete method throws an exception. However, in the case of a hidden
C++ destructor SWIG also doesn't generate a finalizer, and so the most common
call to the delete method is removed. The consequence of this is that the SWIG
objects leak their C++ counterpart and no warnings or exceptions are thrown.

This check looks for the pattern of a memory leaking SWIG generated object and
warns about the potential memory leak. The most straightforward fix is to the
SWIG input code to tell it not to %ignore the C++ code's destructor.