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