-
-
Notifications
You must be signed in to change notification settings - Fork 63
Boxed AnyBox::Native potentially causes memory leaks #469
Comments
Yes, |
@sdroege You sure that any boxed type contains pointer? |
As I know |
See here, which is defined here and has a pointer in there. That pointer is owned and needs to be freed later. Usually for such types there's an
Search for API that has an out parameter that is annotated as Things like the various rectangle types we have would be other cases (but don't contain pointers so can just be dropped as-is), and graphene has a lot of types like this. This code in UninitializedNamed { ref name } => {
let s = format!("{}::uninitialized()", name);
vec![s]
}
I think the solution for this would be to detect |
Strange that |
What do you mean with
That's just a bit weird API, we can ignore that for the bindings. This specific type can never be autogenerated anyway :)
Ok, or that :) The remaining question is then what to do about types like |
I thought about same as |
The problem with |
Oh, now I understand what you meant about |
We could place a |
It's not out parameters that are the problem per-se, but out parameters where the caller allocates. I don't think we have an instance of these currently so would suggest to simply remove this code for boxed types until a need for it arrives. And then we can think of a solution with the concrete case at hand. |
Good, so it's actually used currently. For Now the question is how to distinguish these cases automatically. What we have are the following variants
1. and 3. can't be distinguished automatically. So my proposed solution would be
Opinions? |
CC @GuillaumeGomez @EPashkin :) |
The solution 2. would be the best because it'd allow to finally generate some types which don't provide memory management functions. However I have no idea how difficult it'd be to add it... Otherwise the solution 1. |
I only proposed one solution :) And that does not cause any new types to be generated. It also does not fix any bugs in existing types we generate. |
Agree that we need add |
See #496 for the first part. As you can see, even for init_expression = "|ptr| foo_sys::foo_bar_init(ptr)"
clear_expression = "|ptr| foo_sys::foo_bar_clear(ptr)" |
Agree with only configured |
Going with that then, thanks :) |
I'm not a big fan of the current syntax. I'd prefer to provide a given set of instructions instead of providing strings like that. EDIT: And I didn't comment at the good place I guess since it was on gir that this new syntax was added... |
I can't think of a nicer syntax that covers all cases. In one way or another you need the ability to provide arbitrary Rust code here as the differences in behaviour are too big. |
See here what I'm talking about.
This variant is used whenever
T::uninitialized()
is called, which gir does automatically for boxed types if there's an out parameter that iscaller allocates
.If such a boxed struct is then dropped, nothing will happen according to the code. So if the FFI struct contains pointers that have to be freed, for example, then we would be leaking them.
I didn't check any code yet if we already have such a case, but it seems likely and is obviously wrong.
I'm not sure yet how to implement the same thing correctly.
The text was updated successfully, but these errors were encountered: