[FFmpeg-cvslog] fftools/resources/resman: Don't alloc ResourceManager, fix race
Andreas Rheinhardt
git at videolan.org
Mon Jun 2 01:58:23 EEST 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Jun 1 04:15:58 2025 +0200| [06cd9086c32bf6654f609604ac6131bbd4487803] | committer: Andreas Rheinhardt
fftools/resources/resman: Don't alloc ResourceManager, fix race
The resman_ctx pointer was accessed outside of its guarding
mutex.
Also make the ResourceManager static.
Reviewed-by: softworkz . <softworkz-at-hotmail.com at ffmpeg.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=06cd9086c32bf6654f609604ac6131bbd4487803
---
fftools/resources/resman.c | 37 +++----------------------------------
1 file changed, 3 insertions(+), 34 deletions(-)
diff --git a/fftools/resources/resman.c b/fftools/resources/resman.c
index bce3589169..92e91a39d9 100644
--- a/fftools/resources/resman.c
+++ b/fftools/resources/resman.c
@@ -60,7 +60,7 @@ typedef struct ResourceManagerContext {
static AVMutex mutex = AV_MUTEX_INITIALIZER;
-ResourceManagerContext *resman_ctx = NULL;
+static ResourceManagerContext resman_ctx = { .class = &resman_class };
#if CONFIG_RESOURCE_COMPRESSION
@@ -117,39 +117,11 @@ static int decompress_gzip(ResourceManagerContext *ctx, uint8_t *in, unsigned in
}
#endif
-static ResourceManagerContext *get_resman_context(void)
-{
- ResourceManagerContext *res = resman_ctx;
-
- ff_mutex_lock(&mutex);
-
- if (res)
- goto end;
-
- res = av_mallocz(sizeof(ResourceManagerContext));
- if (!res) {
- av_log(NULL, AV_LOG_ERROR, "Failed to allocate resource manager context\n");
- goto end;
- }
-
- res->class = &resman_class;
- resman_ctx = res;
-
-end:
- ff_mutex_unlock(&mutex);
- return res;
-}
-
-
void ff_resman_uninit(void)
{
ff_mutex_lock(&mutex);
- if (resman_ctx) {
- if (resman_ctx->resource_dic)
- av_dict_free(&resman_ctx->resource_dic);
- av_freep(&resman_ctx);
- }
+ av_dict_free(&resman_ctx.resource_dic);
ff_mutex_unlock(&mutex);
}
@@ -157,14 +129,11 @@ void ff_resman_uninit(void)
char *ff_resman_get_string(FFResourceId resource_id)
{
- ResourceManagerContext *ctx = get_resman_context();
+ ResourceManagerContext *ctx = &resman_ctx;
FFResourceDefinition resource_definition = { 0 };
AVDictionaryEntry *dic_entry;
char *res = NULL;
- if (!ctx)
- return NULL;
-
for (unsigned i = 0; i < FF_ARRAY_ELEMS(resource_definitions); ++i) {
FFResourceDefinition def = resource_definitions[i];
if (def.resource_id == resource_id) {
More information about the ffmpeg-cvslog
mailing list