gtk-rs / gtk-rs-core

Rust bindings for GNOME libraries
https://gtk-rs.org/gtk-rs-core
MIT License
272 stars 105 forks source link

glib: Fix memory leak when aborting tasks #1327

Closed AaronErhardt closed 4 months ago

AaronErhardt commented 4 months ago

Fixes #1326

It's probably not the most beautiful solution, but it should cover all cases.

Maybe it would be nicer to not erase the type from TaskSource in TaskSource::new and wrap the source stored in JoinHandle into ManuallyDrop(TaskSourceStorage(Source)), but I'm not sure whether this is more elegant. The only advantage would be that you could not pass a non-TaskSource Source to JoinHandle::new, which is currently possible and would cause unsafe behavior (due to freeing unknown memory).

sdroege commented 4 months ago

This is unfortunately not thread-safe. I'll take a look at this later or in the next days

sdroege commented 4 months ago

Was actually just a one-liner in the end. See https://github.com/gtk-rs/gtk-rs-core/pull/1328 :)