Moved allocation callback to common.c

Also share it between TCP and UDP