[Beignet] [PATCH 2/2] Runtime: fix caffe segmentation fault when exit.
Song, Ruiling
ruiling.song at intel.com
Wed Jun 22 02:47:26 UTC 2016
> -----Original Message-----
> From: Beignet [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of
> Yang Rong
> Sent: Tuesday, June 21, 2016 12:15 AM
> To: beignet at lists.freedesktop.org
> Cc: Yang, Rong R <rong.r.yang at intel.com>
> Subject: [Beignet] [PATCH 2/2] Runtime: fix caffe segmentation fault when exit.
>
> For static object release, such as context, program, may called after
> delete static variable gbeLoader, so when in gbeLoader's destructor
> function, set the release relative functions to NULL, and when call
> these functions, add a check.
>
> This patch could fix caffe's segmentation fault when exit
>
> Signed-off-by: Yang Rong <rong.r.yang at intel.com>
> ---
> src/cl_gbe_loader.cpp | 5 +++++
> src/cl_program.c | 8 ++++++--
> 2 files changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/src/cl_gbe_loader.cpp b/src/cl_gbe_loader.cpp
> index 2c7ef1e..aa13a3d 100644
> --- a/src/cl_gbe_loader.cpp
> +++ b/src/cl_gbe_loader.cpp
> @@ -320,6 +320,11 @@ struct GbeLoaderInitializer
>
> if (dlhInterp != NULL)
> dlclose(dlhInterp);
> +
> + //When destroy, set the release relative functions
> + //to NULL to avoid dangling pointer visit.
> + compiler_program_clean_llvm_resource = NULL;
> + interp_program_delete = NULL;
In fact, we should reset all the function pointers. But as other functions will not be called anymore, I think it is just safe now.
The whole patchset LGTM
Thanks!
Ruiling
> }
>
> bool compilerLoaded;
> diff --git a/src/cl_program.c b/src/cl_program.c
> index 93eba03..75262db 100644
> --- a/src/cl_program.c
> +++ b/src/cl_program.c
> @@ -112,8 +112,12 @@ cl_program_delete(cl_program p)
> /* Free the program as allocated by the compiler */
> if (p->opaque) {
> if (CompilerSupported())
> - compiler_program_clean_llvm_resource(p->opaque);
> - interp_program_delete(p->opaque);
> + //For static variables release, gbeLoader may have been released, so
> + //compiler_program_clean_llvm_resource and interp_program_delete may
> be NULL.
> + if(compiler_program_clean_llvm_resource)
> + compiler_program_clean_llvm_resource(p->opaque);
> + if(interp_program_delete)
> + interp_program_delete(p->opaque);
> }
>
> p->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
> --
> 2.1.4
>
> _______________________________________________
> Beignet mailing list
> Beignet at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/beignet
More information about the Beignet
mailing list