From 8b11d63ac6aad101dcd436879347d5dacdd320a0 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sat, 11 Jul 2020 17:41:00 +0800 Subject: [PATCH] add func sf_enable_exit_on_oom --- src/sf_func.c | 13 +++++++++++++ src/sf_func.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/src/sf_func.c b/src/sf_func.c index 0175210..8480506 100644 --- a/src/sf_func.c +++ b/src/sf_func.c @@ -41,3 +41,16 @@ int sf_connect_to_server(const char *ip_addr, const int port, int *sock) return 0; } + +static void sf_memory_oom_notify_callback(const size_t curr_size) +{ + logCrit("file: "__FILE__", line: %d, " + "alloc %"PRId64" bytes fail, exiting ...", + __LINE__, (int64_t)curr_size); + SF_G_CONTINUE_FLAG = false; +} + +void sf_enable_exit_on_oom() +{ + g_oom_notify = sf_memory_oom_notify_callback; +} diff --git a/src/sf_func.h b/src/sf_func.h index d91a6a0..fdb0f9b 100644 --- a/src/sf_func.h +++ b/src/sf_func.h @@ -12,6 +12,8 @@ extern "C" { int sf_connect_to_server(const char *ip_addr, const int port, int *sock); +void sf_enable_exit_on_oom(); + #ifdef __cplusplus } #endif