jwharm / java-gi

GObject-Introspection bindings generator for Java
GNU Lesser General Public License v2.1
93 stars 9 forks source link

Copy structs when native code has ownership #124

Closed jwharm closed 1 month ago

jwharm commented 2 months ago

When native code returns a struct or boxed type with transfer-ownership="none", the struct should be copied. For boxed types, use g_boxed_copy; for other types, either use the copy-func annotation (often missing) or heuristics (look for a copy or ref function), and register it with the MemoryCleaner so the copy will be disposed later.

Without this, the struct can be disposed somewhere else and when Java code then tries to use it, the program will segfault.