Fix memory leak due to smart pointer misuse.

bug 11965932

Change-Id: I982b974b3554b0f4dc7a558107703ff605f580e6
diff --git a/cpp/BaseObj.cpp b/cpp/BaseObj.cpp
index 80d9414..2e0a637 100644
--- a/cpp/BaseObj.cpp
+++ b/cpp/BaseObj.cpp
@@ -33,7 +33,7 @@
 
 
 BaseObj::BaseObj(void *id, sp<RS> rs) {
-    mRS = rs;
+    mRS = rs.get();
     mID = id;
 }
 
@@ -44,7 +44,9 @@
 }
 
 BaseObj::~BaseObj() {
-    RS::dispatch->ObjDestroy(mRS->getContext(), mID);
+    if (mRS && mRS->getContext()) {
+        RS::dispatch->ObjDestroy(mRS->getContext(), mID);
+    }
     mRS = NULL;
     mID = NULL;
 }