Small use-after-free fix

Signed-off-by: Uli Schlachter <psychon@znc.in>
Stop using as much of the C API as possible

Signed-off-by: Uli Schlachter <psychon@znc.in>