Fossil SCM

Do not set the RLIMIT_DATA limit in fossil_limit_memory() when built with AddressSanitizer. On Linux the limit made every command of a sanitizer build stop at startup with an out of memory report.

dmestas 2026-11-13 23:39 UTC small-fixes-2
Commit d2e8a7f16814b5e975d68b494e7578dcf8c4955ccb554b9bd8c820291332c641
1 file changed +16 -2
+16 -2
--- src/util.c
+++ src/util.c
@@ -769,24 +769,38 @@
769769
if( zTempDirA ) fossil_path_free(zTempDirA);
770770
#endif
771771
return zTFile;
772772
}
773773
774
+/*
775
+** FOSSIL_ASAN is defined if this is a build with AddressSanitizer, which
776
+** needs more address space for its own use than the heap limit allows.
777
+*/
778
+#if defined(__SANITIZE_ADDRESS__)
779
+# define FOSSIL_ASAN 1
780
+#elif defined(__has_feature)
781
+# if __has_feature(address_sanitizer)
782
+# define FOSSIL_ASAN 1
783
+# endif
784
+#endif
785
+
774786
/*
775787
** Turn memory limits for stack and heap on and off. The argument
776788
** is true to turn memory limits on and false to turn them off.
777789
**
778790
** Memory limits should be enabled at startup, but then turned off
779791
** before starting subprocesses.
780792
*/
781793
void fossil_limit_memory(int onOff){
782794
#if defined(__unix__)
795
+#if defined(RLIMIT_DATA) && !defined(FOSSIL_ASAN)
783796
static sqlite3_int64 origHeap = 10000000000LL; /* 10GB */
797
+#endif
784798
static sqlite3_int64 origStack = 8000000 ; /* 8MB */
785799
struct rlimit x;
786800
787
-#if defined(RLIMIT_DATA)
801
+#if defined(RLIMIT_DATA) && !defined(FOSSIL_ASAN)
788802
getrlimit(RLIMIT_DATA, &x);
789803
if( onOff ){
790804
origHeap = x.rlim_cur;
791805
if( sizeof(void*)<8 || sizeof(x.rlim_cur)<8 ){
792806
x.rlim_cur = 1000000000 ; /* 1GB on 32-bit systems */
@@ -795,11 +809,11 @@
795809
}
796810
}else{
797811
x.rlim_cur = origHeap;
798812
}
799813
setrlimit(RLIMIT_DATA, &x);
800
-#endif /* defined(RLIMIT_DATA) */
814
+#endif /* defined(RLIMIT_DATA) && !defined(FOSSIL_ASAN) */
801815
#if defined(RLIMIT_STACK)
802816
getrlimit(RLIMIT_STACK, &x);
803817
if( onOff ){
804818
origStack = x.rlim_cur;
805819
x.rlim_cur = 8000000; /* 8MB */
806820
--- src/util.c
+++ src/util.c
@@ -769,24 +769,38 @@
769 if( zTempDirA ) fossil_path_free(zTempDirA);
770 #endif
771 return zTFile;
772 }
773
 
 
 
 
 
 
 
 
 
 
 
 
774 /*
775 ** Turn memory limits for stack and heap on and off. The argument
776 ** is true to turn memory limits on and false to turn them off.
777 **
778 ** Memory limits should be enabled at startup, but then turned off
779 ** before starting subprocesses.
780 */
781 void fossil_limit_memory(int onOff){
782 #if defined(__unix__)
 
783 static sqlite3_int64 origHeap = 10000000000LL; /* 10GB */
 
784 static sqlite3_int64 origStack = 8000000 ; /* 8MB */
785 struct rlimit x;
786
787 #if defined(RLIMIT_DATA)
788 getrlimit(RLIMIT_DATA, &x);
789 if( onOff ){
790 origHeap = x.rlim_cur;
791 if( sizeof(void*)<8 || sizeof(x.rlim_cur)<8 ){
792 x.rlim_cur = 1000000000 ; /* 1GB on 32-bit systems */
@@ -795,11 +809,11 @@
795 }
796 }else{
797 x.rlim_cur = origHeap;
798 }
799 setrlimit(RLIMIT_DATA, &x);
800 #endif /* defined(RLIMIT_DATA) */
801 #if defined(RLIMIT_STACK)
802 getrlimit(RLIMIT_STACK, &x);
803 if( onOff ){
804 origStack = x.rlim_cur;
805 x.rlim_cur = 8000000; /* 8MB */
806
--- src/util.c
+++ src/util.c
@@ -769,24 +769,38 @@
769 if( zTempDirA ) fossil_path_free(zTempDirA);
770 #endif
771 return zTFile;
772 }
773
774 /*
775 ** FOSSIL_ASAN is defined if this is a build with AddressSanitizer, which
776 ** needs more address space for its own use than the heap limit allows.
777 */
778 #if defined(__SANITIZE_ADDRESS__)
779 # define FOSSIL_ASAN 1
780 #elif defined(__has_feature)
781 # if __has_feature(address_sanitizer)
782 # define FOSSIL_ASAN 1
783 # endif
784 #endif
785
786 /*
787 ** Turn memory limits for stack and heap on and off. The argument
788 ** is true to turn memory limits on and false to turn them off.
789 **
790 ** Memory limits should be enabled at startup, but then turned off
791 ** before starting subprocesses.
792 */
793 void fossil_limit_memory(int onOff){
794 #if defined(__unix__)
795 #if defined(RLIMIT_DATA) && !defined(FOSSIL_ASAN)
796 static sqlite3_int64 origHeap = 10000000000LL; /* 10GB */
797 #endif
798 static sqlite3_int64 origStack = 8000000 ; /* 8MB */
799 struct rlimit x;
800
801 #if defined(RLIMIT_DATA) && !defined(FOSSIL_ASAN)
802 getrlimit(RLIMIT_DATA, &x);
803 if( onOff ){
804 origHeap = x.rlim_cur;
805 if( sizeof(void*)<8 || sizeof(x.rlim_cur)<8 ){
806 x.rlim_cur = 1000000000 ; /* 1GB on 32-bit systems */
@@ -795,11 +809,11 @@
809 }
810 }else{
811 x.rlim_cur = origHeap;
812 }
813 setrlimit(RLIMIT_DATA, &x);
814 #endif /* defined(RLIMIT_DATA) && !defined(FOSSIL_ASAN) */
815 #if defined(RLIMIT_STACK)
816 getrlimit(RLIMIT_STACK, &x);
817 if( onOff ){
818 origStack = x.rlim_cur;
819 x.rlim_cur = 8000000; /* 8MB */
820

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button