minigbm: mediatek: always provide munmap() with a valid address

Before this change, a NULL pointer could have been passed to munmap(),
making impossible for it to unmap previoulsy mapped memory. After this
change, munmap() always receives a valid pointer.

BUG=b:71835379 b:114699642
TEST=adb shell "am instrument -w --abi armeabi-v7a -e class\
 android.uirendering.cts.testclasses.InfrastructureTests#testScreenshot\
 android.uirendering.cts/android.support.test.runner.AndroidJUnitRunner"

Change-Id: Ic1b15807623209ab28d0d4ed63fe0d6ef2dcc6f8
Signed-off-by: Luigi Santivetti <luigi.santivetti@imagination.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/1221667
Commit-Ready: Kazuhiro Inaba <kinaba@chromium.org>
Tested-by: Pin-chih Lin <johnylin@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
diff --git a/mediatek.c b/mediatek.c
index 3b8ecbf..d319bf9 100644
--- a/mediatek.c
+++ b/mediatek.c
@@ -130,9 +130,13 @@
 {
 	if (vma->priv) {
 		struct mediatek_private_map_data *priv = vma->priv;
-		vma->addr = priv->gem_addr;
+
+		if (priv->cached_addr) {
+			vma->addr = priv->gem_addr;
+			free(priv->cached_addr);
+		}
+
 		close(priv->prime_fd);
-		free(priv->cached_addr);
 		free(priv);
 		vma->priv = NULL;
 	}