return NULL;
}
+static int
+_wayland_tbm_client_fd_is_valid(int fd)
+{
+ long flags;
+
+ if (fd < 0) return 0;
+
+ flags = fcntl(fd, F_GETFD);
+ if (flags < 0) {
+ WL_TBM_LOG_E("fd(%d) is invalid(%m)", fd);
+ close(fd);
+ return 0;
+ }
+
+ return 1;
+}
+
static struct wl_buffer *
_wayland_tbm_client_create_wl_buffer(struct wayland_tbm_client *tbm_client, tbm_surface_h surface, int with_fd)
{
int bufs[TBM_SURF_PLANE_MAX] = { -1, -1, -1, -1};
+ int buf = -1;
struct wl_buffer *wl_buffer = NULL;
int num_buf, i;
tbm_surface_info_s info = {0, };
goto err;
}
- if (with_fd)
- bufs[i] = tbm_bo_export_fd(bo);
- else
- bufs[i] = tbm_bo_export(bo);
+ if (with_fd) {
+ buf = tbm_bo_export_fd(bo);
+ if (!_wayland_tbm_client_fd_is_valid(buf)) {
+ goto err;
+ }
+ }
+ else {
+ buf = tbm_bo_export(bo);
+ }
- if (((with_fd) && (bufs[i] < 0)) ||
- ((!with_fd) && (bufs[i] <= 0))) {
+ if (((with_fd) && (buf < 0)) ||
+ ((!with_fd) && (buf <= 0))) {
WL_TBM_LOG_E("Failed to export(with_fd:%d, bufs:%d)", with_fd, bufs[i]);
goto err;
}
+
+ bufs[i] = buf;
}
wl_array_init(&plane_buf_idx);