hwc: Close acquireFenceFds always.
Close acquireFenceFds always even in case of failures if a layer is either
OVERLAY or FRAMEBUFFER_TARGET to prevent leaks in case of failures.
The framework is *not* responsible for closing acquire fds, for layers
marked as above two.
Change-Id: Ia6c751d3ec25f196f5503120894fc6cc692b9d25
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index 519126f..c2688b5 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -343,9 +343,11 @@
}
if (ctx->mFbDev->post(ctx->mFbDev, fbLayer->handle)) {
ALOGE("%s: ctx->mFbDev->post fail!", __FUNCTION__);
- return -1;
+ ret = -1;
}
}
+
+ closeAcquireFds(list);
return ret;
}
@@ -382,9 +384,11 @@
}
if (!ctx->mExtDisplay->post()) {
ALOGE("%s: ctx->mExtDisplay->post fail!", __FUNCTION__);
- return -1;
+ ret = -1;
}
}
+
+ closeAcquireFds(list);
return ret;
}
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index fe3401b..9e01565 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -346,6 +346,17 @@
return ctx->dpyAttr[HWC_DISPLAY_EXTERNAL].isActive;
}
+void closeAcquireFds(hwc_display_contents_1_t* list) {
+ for(uint32_t i = 0; list && i < list->numHwLayers; i++) {
+ //Close the acquireFenceFds
+ //HWC_FRAMEBUFFER are -1 already by SF, rest we close.
+ if(list->hwLayers[i].acquireFenceFd >= 0) {
+ close(list->hwLayers[i].acquireFenceFd);
+ list->hwLayers[i].acquireFenceFd = -1;
+ }
+ }
+}
+
int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
int fd) {
int ret = 0;
@@ -397,22 +408,15 @@
ALOGD_IF(HWC_UTILS_DEBUG, "%s: time taken for MSMFB_BUFFER_SYNC IOCTL = %d",
__FUNCTION__, (size_t) ns2ms(systemTime() - start));
}
+
if(ret < 0) {
ALOGE("ioctl MSMFB_BUFFER_SYNC failed, err=%s",
strerror(errno));
}
+
for(uint32_t i = 0; i < list->numHwLayers; i++) {
if(list->hwLayers[i].compositionType == HWC_OVERLAY ||
list->hwLayers[i].compositionType == HWC_FRAMEBUFFER_TARGET) {
- //Close the acquireFenceFds
- if(list->hwLayers[i].acquireFenceFd >= 0) {
- close(list->hwLayers[i].acquireFenceFd);
- list->hwLayers[i].acquireFenceFd = -1;
- }
- if(fd >= 0) {
- close(fd);
- fd = -1;
- }
//Populate releaseFenceFds.
if(UNLIKELY(swapzero))
list->hwLayers[i].releaseFenceFd = -1;
@@ -420,12 +424,19 @@
list->hwLayers[i].releaseFenceFd = dup(releaseFd);
}
}
+
+ if(fd >= 0) {
+ close(fd);
+ fd = -1;
+ }
+
if(UNLIKELY(swapzero)){
list->retireFenceFd = -1;
close(releaseFd);
} else {
list->retireFenceFd = releaseFd;
}
+
return ret;
}
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 045ef7f..931a4e7 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -143,6 +143,9 @@
void getActionSafePosition(hwc_context_t *ctx, int dpy, uint32_t& x,
uint32_t& y, uint32_t& w, uint32_t& h);
+//Close acquireFenceFds of all layers of incoming list
+void closeAcquireFds(hwc_display_contents_1_t* list);
+
//Sync point impl.
int hwc_sync(hwc_context_t *ctx, hwc_display_contents_1_t* list, int dpy,
int fd);