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];