Did you check possible memory leaks with valgrind? If you do get_lhs the ref count should be incremented, thus you should use SG_UNREF when not making use of lhs.