g_value_copy is was recently broken
I just spent an afternoon trying to track down why I am seeing memory corruption when copying text through the clipboard in GTK4. gdk_clipboard_set_text (clipboard, text) does something like:
G_VALUE_COLLECT_INIT (&value, G_TYPE_STRING,
args, G_VALUE_NOCOPY_CONTENTS,
&error);
and then later
g_value_copy (&value, &permanent_value);
the gtk code calls
text = ...
gdk_clipboard_set_text (clipboard, text);
g_free (text);
Before March 15, this worked fine, and code that later pasted the clipboard contents from the permanent_value worked fine. Now, we get memory corruption.
The commit to blame is:
commit e3efbd30a20f40e5c2e0c2d7a92ee7221f7bd2a8
Author: Edward Hervey <edward@centricular.com>
Date: Fri May 15 17:28:45 2020 +0200
gvalue: Static strings should not be copied
When doing copies of GValue backed by static strings, the contents should not be copied
which changed the semantics of g_value_copy() to no longer copy strings if they were collected with G_VALUE_NOCOPY_CONTENTS.
I think this is a case of 'not compatible enough', and warrants a revert.