Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Add Quark::from_static_string #591

Closed

Conversation

GuillaumeGomez
Copy link
Member

Follow-up of #590.

cc @sdroege @EPashkin

@sdroege
Copy link
Member

sdroege commented Feb 12, 2020 via email

@GuillaumeGomez
Copy link
Member Author

Then I didn't fully grasp the whole problem. Let's talk about it tomorrow.

@sdroege
Copy link
Member

sdroege commented Feb 13, 2020

The problem is as follows

  • First call: we allocate a string (to_glib_full()) and pass it to the function, the function stores it
  • Second call: we allocate a string and pass it to the function, the function sees that a quark with that name is already registered so does nothing. It leaks the string
  • Third call: see above, another leak

The first might also have happened from another part of the code already, in which case we would directly start with the second call and leak.

The only thing that we could do here is to pass the &'static str directly as a pointer to this function, but that requires the caller to make sure it is NUL-terminated (which is normally not the case, requires writing "foo\0").

@sdroege sdroege closed this Feb 13, 2020
@GuillaumeGomez GuillaumeGomez deleted the qquark-static-str branch February 13, 2020 09:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants