Simplify utils_get_hex_from_color() and plug a possible memory leak in it
Plug a possible memory leak
Fix mismatching allocation and deallocation

When allocation with g_malloc(), the memory should be freed using
g_free(), not plain free().

Also, use g_try_malloc() instead of g_malloc() where the code carefully
handles allocation failures itself.