!14146 [MS][LITE][STABLE]free global infershape buffer when program exit

From: @jpc_chenjianping
Reviewed-by: @zhang_xue_tong,@hangangqiang
Signed-off-by: @zhang_xue_tong
pull/14146/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit f3d5a45245

@ -23,9 +23,12 @@ void RegisterInfer() {
_ReshapePrimType_Reshape(); _ReshapePrimType_Reshape();
} }
#endif #endif
InferShape *g_infer_func; InferShape *g_infer_func = NULL;
__attribute__((constructor(101))) void InitInferFuncBuf() { __attribute__((constructor(101))) void InitInferFuncBuf() {
if (g_infer_func != NULL) {
return;
}
g_infer_func = malloc(PrimType_MAX * sizeof(InferShape)); g_infer_func = malloc(PrimType_MAX * sizeof(InferShape));
if (g_infer_func != NULL) { if (g_infer_func != NULL) {
memset(g_infer_func, 0, PrimType_MAX * sizeof(InferShape)); memset(g_infer_func, 0, PrimType_MAX * sizeof(InferShape));
@ -35,6 +38,14 @@ __attribute__((constructor(101))) void InitInferFuncBuf() {
#endif #endif
} }
__attribute__((destructor)) void DestroyInferFuncBuf() {
if (g_infer_func == NULL) {
return;
}
free(g_infer_func);
g_infer_func = NULL;
}
InferShape GetInferFunc(int prim_type) { InferShape GetInferFunc(int prim_type) {
if (g_infer_func != NULL && prim_type < PrimType_MAX) { if (g_infer_func != NULL && prim_type < PrimType_MAX) {
return g_infer_func[prim_type]; return g_infer_func[prim_type];

Loading…
Cancel
Save