Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes memory leak issues that is described here, but this fix introduces new issues.
Where is leak?
The leak was happening in JNI code that is generated by SWIG. Long and unsigned chat arrays that were used to pass java arrays to C code weren't deallocated.
SWIG_JavaArrayInLonglong
allocates array of longs and that array isn't deallocated. See JNI code:Solution
I worked with SWIG first time, so I am not sure that's correct solution. At least changing
%typemap(freearg) void**;
to%typemap(freearg) long long**;
makes SWIG generate deallocation of long array.I also profiled the library with my fix and I confirm that it fixes leaks.
Problem
There is a least one function (
realm_binary_t_data_set()
) where used long array shouldn't be deallocated. It leads to crash when deallocatingrealm_value_t
asdata
is freed inrealm_binary_t_data_set()
.