aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2021-02-02 19:52:20 +0100
committerSimon Ser <contact@emersion.fr>2021-02-02 19:52:20 +0100
commit7ac2ce25e3bcb7e03bee98dd9dd5757f6bf12d47 (patch)
treeb3fc034dc8499d87d6af4edc504a2afa6e71cf46
parent975d14b799d138ae0f0220b62fc0469ac928dd2f (diff)
render/dmabuf: cleanup on wlr_dmabuf_attributes_copy error
-rw-r--r--render/dmabuf.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/render/dmabuf.c b/render/dmabuf.c
index bed609dd..1940b66e 100644
--- a/render/dmabuf.c
+++ b/render/dmabuf.c
@@ -16,13 +16,22 @@ bool wlr_dmabuf_attributes_copy(struct wlr_dmabuf_attributes *dst,
struct wlr_dmabuf_attributes *src) {
memcpy(dst, src, sizeof(struct wlr_dmabuf_attributes));
- for (int i = 0; i < src->n_planes; ++i) {
+ int i;
+ for (i = 0; i < src->n_planes; ++i) {
dst->fd[i] = fcntl(src->fd[i], F_DUPFD_CLOEXEC, 0);
if (dst->fd[i] < 0) {
wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed");
- return false;
+ goto error;
}
}
return true;
+
+error:
+ for (int j = 0; j < i; j++) {
+ close(dst->fd[i]);
+ dst->fd[j] = -1;
+ }
+ dst->n_planes = 0;
+ return false;
}