From: Matt Corallo Date: Sun, 18 Jul 2021 02:24:24 +0000 (+0000) Subject: Free constructed LDK strings when relevant. X-Git-Tag: v0.0.99.2~18 X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=commitdiff_plain;h=a7fb44f8312609821a58be1d45eb6e3e8f698336 Free constructed LDK strings when relevant. With LDK C Bindings v0.0.99.2, this reduces memory leaks during tests from: 538 allocations remained for 1188720 bytes. to 358 allocations remained for 1141342 bytes. --- diff --git a/gen_type_mapping.py b/gen_type_mapping.py index cbec2ee9..3fb0ba7c 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -183,10 +183,13 @@ class TypeMappingGenerator: ret_conv_name = ty_info.var_name + "_conv", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) else: + free_str = "" + if not holds_ref: + free_str = "\nStr_free(" + ty_info.var_name + "_str);" return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = arg_conv, arg_conv_name = arg_conv_name, arg_conv_cleanup = None, ret_conv = ("LDKStr " + ty_info.var_name + "_str = ", - ";\njstring " + ty_info.var_name + "_conv = " + self.consts.str_ref_to_native_call(ty_info.var_name + "_str." + ty_info.arr_access, ty_info.var_name + "_str." + ty_info.arr_len) + ";"), + ";\njstring " + ty_info.var_name + "_conv = " + self.consts.str_ref_to_native_call(ty_info.var_name + "_str." + ty_info.arr_access, ty_info.var_name + "_str." + ty_info.arr_len) + ";" + free_str), ret_conv_name = ty_info.var_name + "_conv", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) elif ty_info.var_name == "" and not print_void: # We don't have a parameter name, and want one, just call it arg