g_memdup() gets size argument as guint(32bit) instead of gsize(64bit), and may cause vulnerability. g_memdup2() fixes this problem and deprecated g_memdup() with its introduction. Although it is highly unlikely to happen for our usage, it would be better to use a safer approach.
Unfortunately g_memdup2() is introduced in 2.67.3 (this year), so would not be a good idea to assume the linux distribution supports one. This MR uses an inline version if it is not supported.