Update Sdb, adding refcounting and some coverity fixes