aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/memdebug.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-04-08 22:37:27 +0300
committershadchin <shadchin@yandex-team.ru>2022-04-08 22:37:27 +0300
commit1331b4eeb3379e6b60ee2bdec44c6394ee34be24 (patch)
tree57a80b36f47b10b54b9e4acec72661fccfafee5f /contrib/libs/curl/lib/memdebug.c
parent6886c6a225f5b54d62c38bac5b53af7dcaa09fd6 (diff)
downloadydb-1331b4eeb3379e6b60ee2bdec44c6394ee34be24.tar.gz
CONTRIB-2513 Update contrib/libs/curl to 7.76.1
ref:6ca4bf15fd9dd0eb27cbc38bcd575b8251b98a4b
Diffstat (limited to 'contrib/libs/curl/lib/memdebug.c')
-rw-r--r--contrib/libs/curl/lib/memdebug.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/contrib/libs/curl/lib/memdebug.c b/contrib/libs/curl/lib/memdebug.c
index 881ee85c32..050c5d4b2f 100644
--- a/contrib/libs/curl/lib/memdebug.c
+++ b/contrib/libs/curl/lib/memdebug.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -55,9 +55,24 @@ struct memdebug {
*/
FILE *curl_dbg_logfile = NULL;
+static bool registered_cleanup = FALSE; /* atexit registered cleanup */
static bool memlimit = FALSE; /* enable memory limit */
static long memsize = 0; /* set number of mallocs allowed */
+/* 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
+ _exit() comes after the atexit handlers are called. curl/curl#6620 */
+static void curl_dbg_cleanup(void)
+{
+ if(curl_dbg_logfile &&
+ curl_dbg_logfile != stderr &&
+ curl_dbg_logfile != stdout) {
+ fclose(curl_dbg_logfile);
+ }
+ curl_dbg_logfile = NULL;
+}
+
/* this sets the log file name */
void curl_dbg_memdebug(const char *logname)
{
@@ -72,6 +87,8 @@ void curl_dbg_memdebug(const char *logname)
setbuf(curl_dbg_logfile, (char *)NULL);
#endif
}
+ if(!registered_cleanup)
+ registered_cleanup = !atexit(curl_dbg_cleanup);
}
/* This function sets the number of malloc() calls that should return
@@ -91,15 +108,13 @@ static bool countcheck(const char *func, int line, const char *source)
should not be made */
if(memlimit && source) {
if(!memsize) {
- if(source) {
- /* log to file */
- curl_dbg_log("LIMIT %s:%d %s reached memlimit\n",
- source, line, func);
- /* log to stderr also */
- fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
- source, line, func);
- fflush(curl_dbg_logfile); /* because it might crash now */
- }
+ /* log to file */
+ curl_dbg_log("LIMIT %s:%d %s reached memlimit\n",
+ source, line, func);
+ /* log to stderr also */
+ fprintf(stderr, "LIMIT %s:%d %s reached memlimit\n",
+ source, line, func);
+ fflush(curl_dbg_logfile); /* because it might crash now */
errno = ENOMEM;
return TRUE; /* RETURN ERROR! */
}