summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2023-04-24 00:28:48 +0200
committerNiklas Haas <github-daiK1o@haasn.dev>2023-05-25 16:25:33 +0200
commit9fd4ae9529f749010cfd26e58ad2a7141f63b609 (patch)
treed245ede033ed1d6a50e78fcc0053a23083ca28fc /video/out
parent19c5cd92b2584b1f21848cb3d409078ce08a5fdf (diff)
downloadmpv-9fd4ae9529f749010cfd26e58ad2a7141f63b609.tar.bz2
mpv-9fd4ae9529f749010cfd26e58ad2a7141f63b609.tar.xz
vo: make mp_frame_perf thread safe
It was unsafe to return pointer to memory that was freed on another thread, just copy the string to caller owned sturcture. Fixes crashes when displaying passes stats with gpu-next.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/gpu/video.c4
-rw-r--r--video/out/vo.h6
-rw-r--r--video/out/vo_gpu_next.c4
3 files changed, 7 insertions, 7 deletions
diff --git a/video/out/gpu/video.c b/video/out/gpu/video.c
index dbe138c009..0994548034 100644
--- a/video/out/gpu/video.c
+++ b/video/out/gpu/video.c
@@ -3580,7 +3580,9 @@ static void frame_perf_data(struct pass_info pass[], struct mp_frame_perf *out)
if (!pass[i].desc.len)
break;
out->perf[out->count] = pass[i].perf;
- out->desc[out->count] = pass[i].desc.start;
+ strncpy(out->desc[out->count], pass[i].desc.start,
+ sizeof(out->desc[out->count]) - 1);
+ out->desc[out->count][sizeof(out->desc[out->count]) - 1] = '\0';
out->count++;
}
}
diff --git a/video/out/vo.h b/video/out/vo.h
index 55c55df15e..085658f3dc 100644
--- a/video/out/vo.h
+++ b/video/out/vo.h
@@ -164,14 +164,12 @@ struct mp_pass_perf {
};
#define VO_PASS_PERF_MAX 64
+#define VO_PASS_DESC_MAX_LEN 128
struct mp_frame_perf {
int count;
struct mp_pass_perf perf[VO_PASS_PERF_MAX];
- // The owner of this struct does not have ownership over the names, and
- // they may change at any time - so this struct should not be stored
- // anywhere or the results reused
- char *desc[VO_PASS_PERF_MAX];
+ char desc[VO_PASS_PERF_MAX][VO_PASS_DESC_MAX_LEN];
};
struct voctrl_performance_data {
diff --git a/video/out/vo_gpu_next.c b/video/out/vo_gpu_next.c
index 9158479a7c..e37b8cb36e 100644
--- a/video/out/vo_gpu_next.c
+++ b/video/out/vo_gpu_next.c
@@ -769,8 +769,8 @@ static void info_callback(void *priv, const struct pl_render_info *info)
perf->peak = pass->peak;
perf->avg = pass->average;
- talloc_free(frame->desc[index]);
- frame->desc[index] = talloc_strdup(p, pass->shader->description);
+ strncpy(frame->desc[index], pass->shader->description, sizeof(frame->desc[index]) - 1);
+ frame->desc[index][sizeof(frame->desc[index]) - 1] = '\0';
frame->count = index + 1;
pthread_mutex_unlock(&p->perf_lock);