Fix for overlay shared_fd close
The shared_fd should only be closed by the control side. Previously,
the shared_fd would be closed by the data side first then closed again
by the control side. This caused problems when the fd was reused for
a different purpose between the first and second close.
diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp
index 098ac76..8f1aa9d 100644
--- a/liboverlay/overlay.cpp
+++ b/liboverlay/overlay.cpp
@@ -120,7 +120,7 @@
};
static int create_shared_data(overlay_shared_t **shared);
-static void destroy_shared_data(int shared_fd, overlay_shared_t *shared);
+static void destroy_shared_data(int shared_fd, overlay_shared_t *shared, bool closefd);
static int open_shared_data(overlay_data_context_t *ctx);
static void close_shared_data(overlay_data_context_t *ctx);
enum { LOCK_REQUIRED = 1, NO_LOCK_NEEDED = 0 };
@@ -276,7 +276,7 @@
return fd;
}
-static void destroy_shared_data( int shared_fd, overlay_shared_t *shared )
+static void destroy_shared_data( int shared_fd, overlay_shared_t *shared, bool closefd )
{
if (shared == NULL)
return;
@@ -295,7 +295,7 @@
LOGE("Failed to Unmap Overlay Shared Data!\n");
}
- if (close(shared_fd)) {
+ if (closefd && close(shared_fd)) {
LOGE("Failed to Close Overlay Shared Data!\n");
}
}
@@ -332,7 +332,7 @@
static void close_shared_data(overlay_data_context_t *ctx)
{
- destroy_shared_data(ctx->shared_fd, ctx->shared);
+ destroy_shared_data(ctx->shared_fd, ctx->shared, false);
ctx->shared = NULL;
}
@@ -486,7 +486,7 @@
error1:
close(fd);
error:
- destroy_shared_data(shared_fd, shared);
+ destroy_shared_data(shared_fd, shared, true);
return NULL;
}
@@ -514,7 +514,7 @@
pthread_mutex_unlock(&shared->lock);
- destroy_shared_data(obj->shared_fd(), shared);
+ destroy_shared_data(obj->shared_fd(), shared, true);
obj->setShared(NULL);
LOGI("Destroying overlay/fd=%d/obj=%08lx", fd, (unsigned long)overlay);