[Mesa-dev] Double free error on etnaviv driver.
Lucas Stach
l.stach at pengutronix.de
Thu Jan 17 09:40:24 UTC 2019
Hi Sergey,
Am Mittwoch, den 16.01.2019, 13:34 +0300 schrieb Nazarov Sergey:
> Hello!
> I use mesa+etnaviv Gallium driver on iMX6Q based board.
> I have double free error at the end of any application using mesa.
> I've found that the problem comes from current ARM g++ compilers
> (at least from 4.9.4 up to latest ones) which call static objects destructors before
> on_exit handler. So, static builtin_builder builtins destructor frees dynamically allocated
> internal members memory before call of _mesa_glsl_release_builtin_functions(),
> which do that again. Here is a patch to fix the problem:
Do you have a reproducer for this issue? I haven't experienced any
memory corruption issues with etnaviv in a long time. Also this being
shared code, it should also happen on other ARM drivers too.
I gave some applications a quick run under valgrind, which didn't turn
up anything bad immediately, so I would be interested in a way to
clearly demonstrate the issue.
Regards,
Lucas
>
> --- a/src/compiler/glsl/builtin_functions.cpp
> +++ b/src/compiler/glsl/builtin_functions.cpp
> @@ -6268,7 +6268,7 @@ builtin_builder::_vote(const char *intri
> /******************************************************************************/
>
> /* The singleton instance of builtin_builder. */
> -static builtin_builder builtins;
> +static builtin_builder *builtins = NULL;
> static mtx_t builtins_lock = _MTX_INITIALIZER_NP;
>
> /**
> @@ -6279,7 +6279,9 @@ void
> _mesa_glsl_initialize_builtin_functions()
> {
> mtx_lock(&builtins_lock);
> - builtins.initialize();
> + if (!builtins)
> + builtins = new builtin_builder;
> + builtins->initialize();
> mtx_unlock(&builtins_lock);
> }
>
> @@ -6287,7 +6289,9 @@ void
> _mesa_glsl_release_builtin_functions()
> {
> mtx_lock(&builtins_lock);
> - builtins.release();
> + builtins->release();
> + delete builtins;
> + builtins = NULL;
> mtx_unlock(&builtins_lock);
> }
>
> @@ -6297,7 +6301,7 @@ _mesa_glsl_find_builtin_function(_mesa_g
> {
> ir_function_signature *s;
> mtx_lock(&builtins_lock);
> - s = builtins.find(state, name, actual_parameters);
> + s = builtins->find(state, name, actual_parameters);
> mtx_unlock(&builtins_lock);
>
> return s;
> @@ -6309,7 +6313,7 @@ _mesa_glsl_has_builtin_function(_mesa_gl
> ir_function *f;
> bool ret = false;
> mtx_lock(&builtins_lock);
> - f = builtins.shader->symbols->get_function(name);
> + f = builtins->shader->symbols->get_function(name);
> if (f != NULL) {
> foreach_in_list(ir_function_signature, sig, &f->signatures) {
> if (sig->is_builtin_available(state)) {
> @@ -6326,7 +6330,7 @@ _mesa_glsl_has_builtin_function(_mesa_gl
> gl_shader *
> _mesa_glsl_get_builtin_function_shader()
> {
> - return builtins.shader;
> + return builtins ? builtins->shader : NULL;
> }
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list