]> git.bitcoin.ninja Git - ldk-java/commitdiff
Fix double free introduced in 9b9e4369d34e24a9dc7f3f1494865a026ca4
authorMatt Corallo <git@bluematt.me>
Mon, 10 Jan 2022 04:30:00 +0000 (04:30 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 10 Jan 2022 05:04:35 +0000 (05:04 +0000)
This requires correctly setting `holds_ref` as well as handling
`holds_ref` on pointed-to objects in the general-case ret_conv in
`gen_type_mapping.py`.

gen_type_mapping.py
genbindings.py

index 504fbdc0251cea4453cec5652fe4ca311af57f50..c7f75484daa660529eb9b4bb7da81806e577d7d0 100644 (file)
@@ -534,9 +534,12 @@ class TypeMappingGenerator:
                             to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, "ret_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";\n" + self.consts.add_ref("ret_hu_conv", "this") + ";",
                             to_hu_conv_name = "ret_hu_conv",
                             from_hu_conv = (ty_info.var_name + " == null ? 0 : " + self.consts.get_ptr(ty_info.var_name), self.consts.add_ref("this", ty_info.var_name)))
+                ret_conv = ("uint64_t ret_" + ty_info.var_name + " = (uint64_t)", ";")
+                if holds_ref:
+                    ret_conv = (ret_conv[0], " | 1;")
                 return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                     arg_conv = ty_info.rust_obj + "* " + ty_info.var_name + "_conv = (" + ty_info.rust_obj + "*)(" + ty_info.var_name + " & ~1);",
                     arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
-                    ret_conv = ("uint64_t ret_" + ty_info.var_name + " = (uint64_t)", ";"), ret_conv_name = "ret_" + ty_info.var_name,
+                    ret_conv = ret_conv, ret_conv_name = "ret_" + ty_info.var_name,
                     to_hu_conv = "TODO 3", to_hu_conv_name = None, from_hu_conv = None) # its a pointer, no conv needed
             assert False # We should have handled every case by now.
index 5fd2062817370ec9c15134c4a113ccae1a9829fc..1ac132ad9e1b3d21b0b0a824ed2f4ea892155acd 100755 (executable)
@@ -703,6 +703,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
             if check_sfx is not None:
                 write_c("CHECK(" + check_sfx[0] + "owner" + check_sfx[1] + ");\n")
             write_c("\treturn " + accessor[0] + "owner" + accessor[1] + ";\n")
+            holds_ref = True
         else:
             fn_defn = ptr_fn_defn
             write_c("static inline " + fn_defn + "{\n")