Fixed resource leak in xwrapper.c