gralloc4: Delete the gralloc handle when freeing the buffer

Bug: 199336554
Test: Do not observe leaks in heap profiling
Change-Id: Iacab8555a1f425d7746fc7ab0937ddf9b1cf23d8
(cherry picked from commit 4ffbe198a4b30112aa2a29f709de0052750b53ca)
diff --git a/gralloc4/src/allocator/mali_gralloc_ion.cpp b/gralloc4/src/allocator/mali_gralloc_ion.cpp
index dd003c9..4b96743 100644
--- a/gralloc4/src/allocator/mali_gralloc_ion.cpp
+++ b/gralloc4/src/allocator/mali_gralloc_ion.cpp
@@ -523,6 +523,7 @@
 		hnd->fds[i] = -1;
 		hnd->bases[i] = 0;
 	}
+	delete hnd;
 }
 
 static void mali_gralloc_ion_free_internal(buffer_handle_t * const pHandle,
diff --git a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
index e928637..c0f1549 100644
--- a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
+++ b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
@@ -1150,8 +1150,8 @@
 		return -1;
 	}
 
-	mali_gralloc_ion_free(hnd);
 	gralloc_shared_memory_free(hnd);
+	mali_gralloc_ion_free(hnd);
 
 	return 0;
 }
diff --git a/gralloc4/src/core/mali_gralloc_reference.cpp b/gralloc4/src/core/mali_gralloc_reference.cpp
index 57b8f73..880f838 100644
--- a/gralloc4/src/core/mali_gralloc_reference.cpp
+++ b/gralloc4/src/core/mali_gralloc_reference.cpp
@@ -116,8 +116,6 @@
 		{
 			mali_gralloc_dump_buffer_erase(hnd);
 			mali_gralloc_buffer_free(handle);
-			delete handle;
-
 		}
 	}
 	else if (hnd->remote_pid == getpid()) // never unmap buffers that were not imported into this process