From b9cc44ef16d421d09dcae0d5ea7cef2df593efc8 Mon Sep 17 00:00:00 2001 From: xuanyue Date: Fri, 26 Mar 2021 14:21:03 +0800 Subject: [PATCH] add destructor for infer --- 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 46dfe4479b..3f523c17ee 100644 --- a/mindspore/lite/nnacl/infer/infer_register.c +++ b/mindspore/lite/nnacl/infer/infer_register.c @@ -15,15 +15,26 @@ */ #include "nnacl/infer/infer_register.h" -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)); } } +__attribute__((destructor)) void FreeInferFuncBuf() { + 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];