summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-11-11 01:39:59 +0100
committerDudemanguy <random342@airmail.cc>2023-11-14 15:00:00 +0000
commitff7f105c85287c413993c4ea43a556c90e6d7dde (patch)
treea838d64a5d584d80896ed3f0087cbc5c30222ad3 /video
parentd124449c3d51e8431a06380c32bd478928eaefc4 (diff)
downloadmpv-ff7f105c85287c413993c4ea43a556c90e6d7dde.tar.bz2
mpv-ff7f105c85287c413993c4ea43a556c90e6d7dde.tar.xz
vo_gpu_next: guard from cache save conflict
If multiple instances of mpv are closed at the same time, they will write to the same temporary file. Fix that by using unique temporary file.
Diffstat (limited to 'video')
-rw-r--r--video/out/vo_gpu_next.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c
index 37625bb5dd..c59ea8a014 100644
--- a/video/out/vo_gpu_next.c
+++ b/video/out/vo_gpu_next.c
@@ -1557,10 +1557,15 @@ static void save_cache_files(struct priv *p)
if (!target_file)
continue;
- char *tmp = talloc_asprintf(ta_ctx, "%s~", target_file);
- FILE *cache = fopen(tmp, "wb");
- if (!cache)
+ char *tmp = talloc_asprintf(ta_ctx, "%sXXXXXX", target_file);
+ int fd = mkstemp(tmp);
+ if (fd < 0)
continue;
+ FILE *cache = fdopen(fd, "wb");
+ if (!cache) {
+ close(fd);
+ continue;
+ }
int ret = pl_cache_save_file(target_cache, cache);
if (same_cache)
ret += pl_cache_save_file(p->icc_cache, cache);