summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-05-11 16:19:05 +0200
committerwm4 <wm4@nowhere>2014-05-11 16:41:17 +0200
commit342298fd1aa552170a7c1d2271e79894fe0377c2 (patch)
treea1125b3c04dcef674519f8dbf7613ef48ce58adf /video
parent3d530af8eff621fc11a265068e204f0eaac5abd8 (diff)
downloadmpv-342298fd1aa552170a7c1d2271e79894fe0377c2.tar.bz2
mpv-342298fd1aa552170a7c1d2271e79894fe0377c2.tar.xz
wayland: fix unchecked malloc usage
Found by cppcheck. Actually untested. (This is the file drag&drop code, I don't even know which wayland clients support this.)
Diffstat (limited to 'video')
-rw-r--r--video/out/wayland_common.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c
index 55896b8210..679be9c7ef 100644
--- a/video/out/wayland_common.c
+++ b/video/out/wayland_common.c
@@ -1006,26 +1006,32 @@ static int vo_wayland_check_events (struct vo *vo)
size_t str_len = 0;
int has_read = 0;
+ if (!buffer)
+ goto fail;
+
while (0 < (has_read = read(fd.fd, buffer+str_len, to_read))) {
if (buffer_len + to_read < buffer_len) {
MP_ERR(wl, "Integer overflow while reading from fd\n");
- free(buffer);
break;
}
str_len += has_read;
buffer_len += to_read;
- buffer = realloc(buffer, buffer_len);
+ void *ptr = realloc(buffer, buffer_len);
+ if (!ptr)
+ break;
+ buffer = ptr;
if (has_read < to_read) {
buffer[str_len] = 0;
struct bstr file_list = bstr0(buffer);
mp_event_drop_mime_data(vo->input_ctx, "text/uri-list",
file_list);
- free(buffer);
break;
}
}
+ fail:
+ free(buffer);
}
if (fd.revents & POLLHUP) {