node-gtk icon indicating copy to clipboard operation
node-gtk copied to clipboard

Memory error during "new Gtk.RGBA"

Open ghost opened this issue 4 years ago • 4 comments

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 $

ghost avatar Apr 30 '21 06:04 ghost

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.

romgrk avatar Apr 30 '21 08:04 romgrk

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.

ghost avatar May 04 '21 13:05 ghost

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

romgrk avatar May 04 '21 13:05 romgrk

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.

romgrk avatar May 12 '21 21:05 romgrk