sdm: Close fds only if they are valid
Close poll and release fence fds only if they are valid.
Change-Id: Ia08c211a1a2e059c8ad60d8242bc6598a127cabf
diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp
index 97aa5c9..348d22f 100644
--- a/sdm/libs/core/fb/hw_device.cpp
+++ b/sdm/libs/core/fb/hw_device.cpp
@@ -444,7 +444,9 @@
DLOGI_IF(kTagDriverConfig, "retire_fence_fd %d", stack->retire_fence_fd);
DLOGI_IF(kTagDriverConfig, "*******************************************************************");
- Sys::close_(mdp_commit.release_fence);
+ if (mdp_commit.release_fence >= 0) {
+ Sys::close_(mdp_commit.release_fence);
+ }
if (synchronous_commit_) {
// A synchronous commit can be requested when changing the display mode so we need to update
diff --git a/sdm/libs/core/fb/hw_primary.cpp b/sdm/libs/core/fb/hw_primary.cpp
index d5c913d..3c61947 100644
--- a/sdm/libs/core/fb/hw_primary.cpp
+++ b/sdm/libs/core/fb/hw_primary.cpp
@@ -223,7 +223,10 @@
pthread_join(event_thread_, NULL);
for (int event = 0; event < kNumDisplayEvents; event++) {
- Sys::close_(poll_fds_[event].fd);
+ int &fd = poll_fds_[event].fd;
+ if (fd >= 0) {
+ Sys::close_(fd);
+ }
}
return HWDevice::Deinit();