From 41698dbf39f08c4a2753c67f4b26e88bb75aabbd Mon Sep 17 00:00:00 2001 From: chenjianping Date: Fri, 26 Mar 2021 10:36:22 +0800 Subject: [PATCH] free buffer when program exit --- mindspore/lite/nnacl/infer/infer_register.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/mindspore/lite/nnacl/infer/infer_register.c b/mindspore/lite/nnacl/infer/infer_register.c index 34c8ce13c3..d353b1f551 100644 --- a/mindspore/lite/nnacl/infer/infer_register.c +++ b/mindspore/lite/nnacl/infer/infer_register.c @@ -23,9 +23,12 @@ void RegisterInfer() { _ReshapePrimType_Reshape(); } #endif -InferShape *g_infer_func; +InferShape *g_infer_func = NULL; __attribute__((constructor(101))) void InitInferFuncBuf() { + if (g_infer_func != NULL) { + return; + } g_infer_func = malloc(PrimType_MAX * sizeof(InferShape)); if (g_infer_func != NULL) { memset(g_infer_func, 0, PrimType_MAX * sizeof(InferShape)); @@ -35,6 +38,14 @@ __attribute__((constructor(101))) void InitInferFuncBuf() { #endif } +__attribute__((destructor)) void DestroyInferFuncBuf() { + if (g_infer_func == NULL) { + return; + } + free(g_infer_func); + g_infer_func = NULL; +} + InferShape GetInferFunc(int prim_type) { if (g_infer_func != NULL && prim_type < PrimType_MAX) { return g_infer_func[prim_type];