Fixes some memory leaks in qnode