There are a number of methods used by JNI for managing arrays. GetPrimitiveArrayCritical, NewByteArray, etc. When trying to create a jni.cfg, I can seem to figure out how to enter them in the cfg xml so that they are recognized. example:
I have a similar issue.
I have many classes in C++ that have getReadLock() and getWriteLock() and unLock().
I would like to use a 'resource' token in the cfg file to try and catch
the act of not releasing a lock.
When I have a cfg file like this:
<?xml version="1.0"?>
<def>
<resource>
<alloc>getReadLock</alloc>
<dealloc>releaseLock</dealloc>
<dealloc>unLock</dealloc>
</resource>
<resource>
<alloc>getWriteLock</alloc>
<dealloc>releaseLock</dealloc>
<dealloc>unLock</dealloc>
</resource>
</def>
all of the 'standalone' items are recognized, ( getReadLock() ; ),
but the another types of references are not
ptr->getReadLock() ;
Also I have these lock functions in many many classes. Is there a way to write the cfg file to catch all classes of getReadLock(), etc ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are a number of methods used by JNI for managing arrays. GetPrimitiveArrayCritical, NewByteArray, etc. When trying to create a jni.cfg, I can seem to figure out how to enter them in the cfg xml so that they are recognized. example:
When I use this config and the source makes references like:
cppcheck doesn't identify the line unless I remove the env-> reference. Is there a way to put this in a cfg?
TIA,
Bill
You have to tweak your configuration (see attachment jni.cfg).
Then, the following test case:
void foo()
{
ubyte ivData = (ubyte )GetPrimitiveArrayCritical(10, 0);
}
gives
$ cppcheck --library=jni jni_test.cpp
Checking jni_test.cpp...
[jni_test.cpp:4]: (error) Memory leak: ivData
Last edit: orbitcowboy 2015-09-18
You need to specify the scope where the function is declared.
Configuration:
Testcode:
Output from Cppcheck:
I have a similar issue.
I have many classes in C++ that have getReadLock() and getWriteLock() and unLock().
I would like to use a 'resource' token in the cfg file to try and catch
the act of not releasing a lock.
When I have a cfg file like this:
<?xml version="1.0"?>
<def>
<resource>
<alloc>getReadLock</alloc>
<dealloc>releaseLock</dealloc>
<dealloc>unLock</dealloc>
</resource>
<resource>
<alloc>getWriteLock</alloc>
<dealloc>releaseLock</dealloc>
<dealloc>unLock</dealloc>
</resource>
</def>
all of the 'standalone' items are recognized, ( getReadLock() ; ),
but the another types of references are not
ptr->getReadLock() ;
Also I have these lock functions in many many classes. Is there a way to write the cfg file to catch all classes of getReadLock(), etc ?