Use g_memdup2 if available and fallback if not
The "old" g_memdup()
is deprecated in new glib so we need to switch to new one to be able to build without warnings.
The fallback for both autotools and meson are in place so it should work also on the older versions.