Fix hypothetical double-own in hidl_vec.

To my knowledge, no one has hit this, but this type (probably unwisely)
allows itself to be empty w/ null buffer or empty w/ non-null buffer
(e.g. via setExternal/resize(0)). So, releaseData should be checking for
null buffer, not size 0.

Bug: 152911913
Test: libhidl_test
Change-Id: I5792b5aac5b3278333a75ff84f09d3d5e5b3a8a2
diff --git a/test_main.cpp b/test_main.cpp
index e4cdd29..0a1e97b 100644
--- a/test_main.cpp
+++ b/test_main.cpp
@@ -222,6 +222,24 @@
     EXPECT_ARRAYEQ(v3, array, v3.size());
 }
 
+TEST_F(LibHidlTest, VecReleaseTest) {
+    // this test indicates an inconsistency of behaviors which is undesirable.
+    // Perhaps hidl-vec should always allocate an empty vector whenever it
+    // exposes its data. Alternatively, perhaps it should always free/reject
+    // empty vectors and always return nullptr for this state. While this second
+    // alternative is faster, it makes client code harder to write, and it would
+    // break existing client code.
+    using android::hardware::hidl_vec;
+
+    hidl_vec<int32_t> empty;
+    EXPECT_EQ(nullptr, empty.releaseData());
+
+    empty.resize(0);
+    int32_t* data = empty.releaseData();
+    EXPECT_NE(nullptr, data);
+    delete data;
+}
+
 TEST_F(LibHidlTest, VecIterTest) {
     int32_t array[] = {5, 6, 7};
     android::hardware::hidl_vec<int32_t> hv1 = std::vector<int32_t>(array, array + 3);