Fix segfault on errors emitting.

Function 'pkg_emit_error' calls for pkg_emit_event twice and, moreover,
the first time it is called with uninitialized buffer, hence causing
SIGSEGV while accessing this buffer further. This patch fixes it.