aboutsummaryrefslogtreecommitdiffstats
path: root/main/asterisk/musl-outofmem-handling.patch
blob: 24b1a9ec742ae710cc61902bd0c6d96b40e03666 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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))