Fix a memory leak in 'sk_dup' in the case a realloc() fails. Also, tidy up