This segfault happens when I am running:
alignarray *aligns = g_ptr_array_sized_new(N_DEFAULT_ALIGNS);
…, where alignarray is just GPtrArray.
This statement runs successfully for several times, and then suddenly fails, reporting “No source available for g_slice_alloc()“. After searching, I try to use export G_SLICE=always-malloc to disable the slicing memory allocation, but it still fails…
Or is it because somewhere in the code I did not handle the memory well? Currently my problem is that I do not know where to debug. I tried gdb and valgrind, but both cannot help.
It’s strange that setting
G_SLICE=always-mallocstill gives this problem. The slice allocator is a way of avoiding the overhead of allocating memory by reusing memory for actions that are similarly sized.If you allocate 100 things that are 8 bytes long (like 2 pointers on 32-bit) free those and allocate some more then you’ll reuse the same memory. The big caveat is that you must ensure that memory that was allocated using the slice allocator is freed using the slice allocator functions – directly through
g_slice_freeor indirectly through something likeg_object_unrefCheck in your code that you’re not freeing other instances ofGPtrArray(or something of a similar size) withg_freeYou may be able to identify where the erroneous freeing or corruption is occurring using valgrind. When using valgrind you must set
G_SLICE=always-malloc