]> git.bitcoin.ninja Git - ldk-java/commitdiff
Don't FREE things when we holds_ref if we're not calling *_free
authorMatt Corallo <git@bluematt.me>
Thu, 29 Apr 2021 18:28:36 +0000 (18:28 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 1 May 2021 00:11:31 +0000 (00:11 +0000)
After this we still only have minor leaks across 128 runs of
HumanObjectPeerTest:
   314 allocations remained for 1126840 bytes.

gen_type_mapping.py

index 475e132bc447a1b71133b763181dd277c7af19e8..ba29e0af96f93136e31e634a45be8da3e2fca929 100644 (file)
@@ -310,7 +310,7 @@ class TypeMappingGenerator:
                         base_conv = base_conv + "\n" + ty_info.var_name + "_conv = " + ty_info.rust_obj.replace("LDK", "") + "_clone((" + ty_info.rust_obj + "*)(((uint64_t)" + ty_info.var_name + ") & ~1));"
                     elif needs_full_clone:
                         base_conv = base_conv + "\n// Warning: we may need a move here but no clone is available for " + ty_info.rust_obj
-                if not needs_full_clone and ty_info.rust_obj != "LDKu8slice":
+                if not needs_full_clone and ty_info.rust_obj != "LDKu8slice" and (not holds_ref or is_free):
                     # Don't bother free'ing slices passed in - Rust doesn't auto-free the
                     # underlying unlike Vecs, and it gives Java more freedom.
                     base_conv = base_conv + "\nFREE((void*)" + ty_info.var_name + ");"