exynos: gralloc3: Bring back proper support for GRALLOC_USE_ASHMEM_METADATA

* See https://android.googlesource.com/platform/hardware/google/gchips/+/85d965a6394d0a06ba9aa9bd1e04562013c22832%5E%21/#F1

Change-Id: Ibb4fc65f816b31ea5da1d9e1516bc384db32a9c6
diff --git a/gralloc3/src/mali_gralloc_reference.cpp b/gralloc3/src/mali_gralloc_reference.cpp
index addbc53..748d0e0 100644
--- a/gralloc3/src/mali_gralloc_reference.cpp
+++ b/gralloc3/src/mali_gralloc_reference.cpp
@@ -146,6 +146,17 @@
 				AERR("Unregistering/Releasing unknown buffer is not supported. Flags = %d", hnd->flags);
 			}
 
+#if GRALLOC_USE_ASHMEM_METADATA == 1
+			/*
+			 * Close shared attribute region file descriptor. It might seem strange to "free"
+			 * this here since this can happen in a client process, but free here is nothing
+			 * but unmapping and closing the duplicated file descriptor. The original ashmem
+			 * fd instance is still open until alloc_device_free() is called. Even sharing
+			 * of gralloc buffers within the same process should have fds dup:ed.
+			 */
+			gralloc_buffer_attr_free(hnd);
+#endif
+
 			hnd->base = 0;
 		}
 	}