← Commit list

06e16167d6

Daniel Stenberg
Daniel Stenberg
2025-11-28
SUCCESS Duration: 146s

Subject

memdebug: buffer output data

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

lib/memdebug.c+21 -3
@@ -62,6 +62,10 @@ static long memsize = 0; /* set number of mallocs allowed */
static struct backtrace_state *btstate;
#endif
+#define KEEPSIZE 10000
+static char membuf[KEEPSIZE];
+static size_t memwidx = 0; /* write index */
+
/* LeakSantizier (LSAN) calls _exit() instead of exit() when a leak is detected
on exit so the logfile must be closed explicitly or data could be lost.
Though _exit() does not call atexit handlers such as this, LSAN's call to
@@ -71,6 +75,8 @@ static void curl_dbg_cleanup(void)
if(curl_dbg_logfile &&
curl_dbg_logfile != stderr &&
curl_dbg_logfile != stdout) {
+ if(memwidx)
+ fwrite(membuf, 1, memwidx, curl_dbg_logfile);
/* !checksrc! disable BANNEDFUNC 1 */
fclose(curl_dbg_logfile);
}
@@ -506,7 +512,7 @@ int curl_dbg_fclose(FILE *file, int line, const char *source)
void curl_dbg_log(const char *format, ...)
{
char buf[1024];
- int nchars;
+ size_t nchars;
va_list ap;
if(!curl_dbg_logfile)
@@ -519,8 +525,20 @@ void curl_dbg_log(const char *format, ...)
if(nchars > (int)sizeof(buf) - 1)
nchars = (int)sizeof(buf) - 1;
- if(nchars > 0)
- fwrite(buf, 1, (size_t)nchars, curl_dbg_logfile);
+ if(nchars > 0) {
+ if(KEEPSIZE - nchars < memwidx) {
+ /* flush */
+ fwrite(membuf, 1, memwidx, curl_dbg_logfile);
+ fflush(curl_dbg_logfile);
+ memwidx = 0;
+ }
+ if(memwidx) {
+ /* the previous line ends with a newline */
+ DEBUGASSERT(membuf[memwidx - 1] == '\n');
+ }
+ memcpy(&membuf[memwidx], buf, nchars);
+ memwidx += nchars;
+ }
}
#endif /* CURLDEBUG */