Merge cherrypicks of [16074852, 16074853] into sc-qpr1-d-release.

Change-Id: I32fadccbc4b159436b3e631e762d070843077608
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..d82ff8c 100644
--- a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
+++ b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp
@@ -1118,8 +1118,6 @@
 	{
 		private_handle_t *hnd = (private_handle_t *)pHandle[i];
 
-		mali_gralloc_dump_buffer_add(hnd);
-
 		if (shared)
 		{
 			/*each buffer will share the same backing store id.*/
@@ -1150,8 +1148,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