summaryrefslogtreecommitdiffstats
path: root/main/asterisk/musl-outofmem-handling.patch
diff options
context:
space:
mode:
Diffstat (limited to 'main/asterisk/musl-outofmem-handling.patch')
-rw-r--r--main/asterisk/musl-outofmem-handling.patch52
1 files changed, 52 insertions, 0 deletions
diff --git a/main/asterisk/musl-outofmem-handling.patch b/main/asterisk/musl-outofmem-handling.patch
new file mode 100644
index 000000000..24b1a9ec7
--- /dev/null
+++ b/main/asterisk/musl-outofmem-handling.patch
@@ -0,0 +1,52 @@
+--- asterisk-12.1.0.orig/include/asterisk/utils.h
++++ asterisk-12.1.0/include/asterisk/utils.h
+@@ -25,7 +25,6 @@
+
+ #include "asterisk/network.h"
+
+-#include <execinfo.h>
+ #include <time.h> /* we want to override localtime_r */
+ #include <unistd.h>
+ #include <string.h>
+@@ -480,25 +479,13 @@
+ #define ast_free free
+ #define ast_free_ptr ast_free
+
+-/*
+- * This buffer is in static memory. We never intend to read it,
+- * nor do we care about multiple threads writing to it at the
+- * same time. We only want to know if we're recursing too deep
+- * already. 60 entries should be more than enough. Function
+- * call depth rarely exceeds 20 or so.
+- */
+-#define _AST_MEM_BACKTRACE_BUFLEN 60
+-extern void *_ast_mem_backtrace_buffer[_AST_MEM_BACKTRACE_BUFLEN];
+-
+-/*
+- * Ok, this sucks. But if we're already out of mem, we don't
+- * want the logger to create infinite recursion (and a crash).
+- */
+ #define MALLOC_FAILURE_MSG \
+ do { \
+- if (backtrace(_ast_mem_backtrace_buffer, _AST_MEM_BACKTRACE_BUFLEN) < _AST_MEM_BACKTRACE_BUFLEN) { \
+- ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file); \
+- } \
++ extern int __thread _ast_out_of_memory; \
++ if (_ast_out_of_memory) break; \
++ _ast_out_of_memory = 1; \
++ ast_log(LOG_ERROR, "Memory Allocation Failure in function %s at line %d of %s\n", func, lineno, file); \
++ _ast_out_of_memory = 0; \
+ } while (0)
+
+ /*!
+--- asterisk-12.1.0.orig/main/hashtab.c
++++ asterisk-12.1.0/main/hashtab.c
+@@ -44,7 +44,7 @@
+
+
+ #ifndef __AST_DEBUG_MALLOC
+-void *_ast_mem_backtrace_buffer[_AST_MEM_BACKTRACE_BUFLEN];
++int __thread _ast_out_of_memory;
+ #endif
+
+ #if (defined(MALLOC_DEBUG) && !defined(STANDALONE))