diff --git a/libc/malloc/amalloc.c b/libc/malloc/amalloc.c index c8579d4f2..2cd8001e9 100644 --- a/libc/malloc/amalloc.c +++ b/libc/malloc/amalloc.c @@ -70,11 +70,11 @@ static NPTR allocp; /*search ptr*/ static NPTR alloct; /*arena top*/ static NPTR allocx; /*for benefit of realloc*/ +static int debug_level = DEBUG; #if DEBUG #define ASSERT(p) if(!(p))malloc_assert_fail(#p,__LINE__);else {} #define debug(...) do { if (debug_level > 1) __dprintf(__VA_ARGS__); } while (0) #define debug2(...) do { if (debug_level > 2) __dprintf(__VA_ARGS__); } while (0) -static int debug_level = DEBUG; static void malloc_assert_fail(char *s, int); static void malloc_show_heap(void); static int malloc_check_heap(void); @@ -335,6 +335,7 @@ malloc_show_heap(void) unsigned int size, alloc = 0, free = 0; static unsigned int maxalloc; + if (!debug_level) return; debug2("--- heap size ---\n"); malloc_check_heap(); for(p = (NPTR)&allocs[0]; clearbusy(next(p)) > p; p=clearbusy(next(p))) { diff --git a/libc/malloc/dprintf.c b/libc/malloc/dprintf.c index fbd7e9ba4..eda959cff 100644 --- a/libc/malloc/dprintf.c +++ b/libc/malloc/dprintf.c @@ -44,8 +44,12 @@ int __dprintf(const char *fmt, ...) char b[80]; static int fd = -1; - if (fd < 0) - fd = open(_PATH_CONSOLE, O_WRONLY); + if (fd < 0) { + if (!isatty(STDERR_FILENO)) + fd = STDERR_FILENO; + else + fd = open(_PATH_CONSOLE, O_WRONLY); + } va_start(va, fmt); for (n = 0; *fmt; fmt++) { if (*fmt == '%') { diff --git a/libc/malloc/v7malloc.c b/libc/malloc/v7malloc.c index cdf88775f..04842ffff 100644 --- a/libc/malloc/v7malloc.c +++ b/libc/malloc/v7malloc.c @@ -59,11 +59,11 @@ static NPTR allocp; /*search ptr*/ static NPTR alloct; /*arena top*/ static NPTR allocx; /*for benefit of realloc*/ +static int debug_level = DEBUG; #if DEBUG #define ASSERT(p) if(!(p))malloc_assert_fail(#p,__LINE__);else {} #define debug(...) do { if (debug_level > 1) __dprintf(__VA_ARGS__); } while (0) #define debug2(...) do { if (debug_level > 2) __dprintf(__VA_ARGS__); } while (0) -static int debug_level = DEBUG; static void malloc_assert_fail(char *s, int); static void malloc_show_heap(void); static int malloc_check_heap(void); @@ -308,6 +308,7 @@ malloc_show_heap(void) unsigned int size, alloc = 0, free = 0; static unsigned int maxalloc; + if (!debug_level) return; debug2("--- heap size ---\n"); malloc_check_heap(); for(p = (NPTR)&allocs[0]; clearbusy(next(p)) > p; p=clearbusy(next(p))) {