romgrk / node-gtk

GTK+ bindings for NodeJS (via GObject introspection)
MIT License
494 stars 42 forks source link

Memory error during "new Gtk.RGBA" #290

Open ghost opened 3 years ago

ghost commented 3 years ago

When I run the code below, I get an error about 70000 iterations.

const GNode = require('node-gtk')
const Gdk = GNode.require('Gdk', '3.0')

let i = 0;
for(let i = 0; ; i++) {
    console.log(i)
    new Gdk.RGBA({red: 255/255, green: 235/255, blue: 51/255, alpha: 1})
}

Output 1: .... 76352 76353 76354 76355 76356 76357 Segmentation fault $

Output 2: .... 71441 71442 71443 71444 71445 71446 71447 71448

MEMORY-ERROR: [16117]: GSlice: assertion failed: sinfo->n_allocated > 0 Aborted $

romgrk commented 3 years ago

Thanks for the report, I had already seen a few of these errors but wasn't sure where they were coming from. I'll investigate what's going on.

ghost commented 3 years ago

https://github.com/romgrk/node-gtk/issues/213

The error does not occur as a result of trying "G_SLICE=always-malloc", the solution in the above article.

romgrk commented 3 years ago

Got it. We can probably skip the issue by using malloc directly rather than g_slice_alloc.

romgrk commented 3 years ago

Update on this, it seems that we had already migrated away from g_slice_alloc to malloc.

https://github.com/romgrk/node-gtk/blob/c3dc55d7a6242801187f83fc068c1f74d34fead8/src/boxed.cc#L186

This is bad news because it means the bug is upstream. After some debugging, it appears that GLib's slice allocator is choking at various points in this method, usually when handling the SlabInfo struct:

https://github.com/GNOME/glib/blob/c0b339372cf3cf29cc8fee212a2debc41ea93cd2/glib/gslice.c#L1386

Here is one place where it aborts:

https://github.com/GNOME/glib/blob/c0b339372cf3cf29cc8fee212a2debc41ea93cd2/glib/gslice.c#L1398

I'll see if I can get some feedback from GLib or I'll open an issue with them soon.