glib2 2.59 introduces a memory leak with error-setting and g_strerror()
Description of problem: Beginning with glib2 2.59 which landed in Rawhide over the weekend, my libmodulemd CI tests started failing because they run memory-leak detection. I narrowed down the minimal reproducer to a short program using glib2 (see below).
Version-Release number of selected component (if applicable): glib2-2.59.0-1.fc30.x86_64
How reproducible: Every time
Steps to Reproduce:
- Compile the reproducer below.
- Run the reproducer under valgrind.
Actual results:
==4268== 29 bytes in 1 blocks are definitely lost in loss record 6 of 16
==4268== at 0x483880B: malloc (vg_replace_malloc.c:309)
==4268== by 0x48A3AD5: g_malloc (in /usr/lib64/libglib-2.0.so.0.5900.0)
==4268== by 0x487D418: g_convert_with_iconv (in /usr/lib64/libglib-2.0.so.0.5900.0)
==4268== by 0x487D70B: g_convert (in /usr/lib64/libglib-2.0.so.0.5900.0)
==4268== by 0x487D842: ??? (in /usr/lib64/libglib-2.0.so.0.5900.0)
==4268== by 0x487DFD3: g_locale_to_utf8 (in /usr/lib64/libglib-2.0.so.0.5900.0)
==4268== by 0x48BE5C7: g_strerror (in /usr/lib64/libglib-2.0.so.0.5900.0)
==4268== by 0x4011C7: main (in /root/gstrerror)
Expected results: No memory leaks, just as it was with glib2-2.58.2-1.fc29.x86_64
Additional info:
== Minimal reproducer ==
#include <glib.h>
#include <errno.h>
#define MODULEMD_ERROR modulemd_error_quark ()
GQuark
modulemd_error_quark (void)
{
return g_quark_from_static_string ("modulemd-error-quark");
}
enum ModulemdError
{
MODULEMD_ERROR_UPGRADE,
MODULEMD_ERROR_VALIDATE,
MODULEMD_ERROR_FILE_ACCESS
};
int main (int argc, char **argv)
{
g_autoptr (GError) error = NULL;
g_set_error (&error,
MODULEMD_ERROR,
MODULEMD_ERROR_FILE_ACCESS,
"Failed to open file: %s",
g_strerror (ENOENT));
}
Compile with:
gcc -o gstrerror gstrerror.c `pkgconf --libs --cflags glib-2.0`
Run with:
valgrind --leak-check=full ./gstrerror