Skip to content

Commit

Permalink
Fix memory leak in COMLateBindingObject#getStringProperty
Browse files Browse the repository at this point in the history
Variants that hold strings utilize a BSTR. BSTRs are special in the sense, that
they are allocated by SysAllocString and freed by SysFreeString and the memory
needs to be explicitly cleared.

For Variants this is handled by VariantClear. VariantClear clears the data
contained in the Variant and frees that data (not the Variant itself!). The
Variant structure is caller allocated and in JNA located in auto-allocated
memory and does not need to be explicitly freed.

This closes java-native-access#867
  • Loading branch information
matthiasblaesing committed Oct 29, 2017
1 parent 8b0f6b1 commit db34ea0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Features
Bug Fixes
---------
* [#863](https://github.com/java-native-access/jna/pull/863): Fix ARM softfloat/hardfloat detection by modifying armSoftFloat condition in ELFAnalyser. Before this fix a softfloat binary could be misdetected as hardfloat. - [@kunkun26](https://github.com/kunkun26).
* [#867](https://github.com/java-native-access/jna/issues/867): Fix memory leak in `COMLateBindingObject#getStringProperty` - [@matthiasblaesing](https://github.com/matthiasblaesing).

Release 4.5.0
=============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ protected String getStringProperty(String propertyName) {
this.oleMethod(OleAuto.DISPATCH_PROPERTYGET, result,
this.getIDispatch(), propertyName);

return result.stringValue();
String res = result.stringValue();

OleAuto.INSTANCE.VariantClear(result);

return res;
}

/**
Expand Down

0 comments on commit db34ea0

Please sign in to comment.