Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC crash with '-DMEMDEBUG_LOG_SYNC' #828

Closed
gvanem opened this issue May 25, 2016 · 6 comments
Closed

MSVC crash with '-DMEMDEBUG_LOG_SYNC' #828

gvanem opened this issue May 25, 2016 · 6 comments

Comments

@gvanem
Copy link
Contributor

gvanem commented May 25, 2016

Building libcurl with -DCURLDEBUG and -DMEMDEBUG_LOG_SYNC for me causes crash in lib/memdebug.c inside curl_memdebug():

    setvbuf(logfile, (char *)NULL, _IOLBF, 0);

I.e. Dr. Watson triggers a run-time check followed by a crash. But this seems to work as intended:

    setvbuf(logfile, (char *)NULL, _IONBF, 0);

Anybody who can confirm this?

This seems to be the same as this Stackoverflow issue. I'm using MSVC-2015 (cl 19.00.23506 for x86) on Win-10.

@dfandrich
Copy link
Contributor

I'm guessing the issue has to do with the size 0 passed in when line buffering; does it work if you pass in 1024 for example? In any case, unbuffering this stream is just as good (if not actually a better) of a solution in this case.

@gvanem
Copy link
Contributor Author

gvanem commented May 25, 2016

does it work if you pass in 1024 for example?

It does.

Not sure what you mean by unbuffering this stream, but trying with this:

--- a/memdebug.c 2016-05-01 22:05:17
+++ b/memdebug.c 2016-05-25 19:41:33
@@ -118,9 +118,18 @@
     else
       logfile = stderr;
 #ifdef MEMDEBUG_LOG_SYNC
-    /* Flush the log file after every line so the log isn't lost in a crash */
+    /* Flush the log file after every line so the log isn't lost in a crash.
+     * For Win32, the mode *must* be _IONBF. Otherwise Dr. Watson triggers a
+     * run-time check followed by a crash.
+     *   Refs: https://msdn.microsoft.com/en-us/library/86cebhfs.aspx
+     *         http://stackoverflow.com/questions/15972550/what-is-the-use-of-setvbuf-in-an-applicationexecutable
+     */
+#if defined(WIN32)
+    setvbuf(logfile, (char *)NULL, _IONBF, 0);
+#else
     setvbuf(logfile, (char *)NULL, _IOLBF, 0);
 #endif
+#endif
   }
 }

seems okay.

@dfandrich
Copy link
Contributor

I was talking about using _IONBF unconditionally, which sets the stream unbuffered. Don't bother making it conditional, just use _IONBF unconditionally, either the way you have it or the slightly simpler setbuf(logfile, (char*)NULL);

@gvanem
Copy link
Contributor Author

gvanem commented May 25, 2016

Ah, yes this works:

--- a/memdebug.c 2016-05-01 22:05:17
+++ b(memdebug.c 2016-05-25 23:10:57
@@ -119,7 +119,7 @@
       logfile = stderr;
 #ifdef MEMDEBUG_LOG_SYNC
     /* Flush the log file after every line so the log isn't lost in a crash */
-    setvbuf(logfile, (char *)NULL, _IOLBF, 0);
+    setbuf(logfile, (char *)NULL);
 #endif
   }
 }

@bagder bagder closed this as completed in 9a15935 May 30, 2016
@bagder
Copy link
Member

bagder commented May 30, 2016

Thanks!

@gvanem
Copy link
Contributor Author

gvanem commented Jul 6, 2017

This issue seems to have surfaced once again. Now in C-ares when CURLDEBUG is in effect.
Turned out to be an user-error; I set %CARES_MEMDEBUG to a non-existing directory/file. I fixed it simply by:

--- a/memdebug.c 2017-05-25 14:03:18
+++ b/memdebug.c 2017-07-06 18:03:24
@@ -115,6 +115,7 @@
       logfile = stderr;
 #ifdef MEMDEBUG_LOG_SYNC
     /* Flush the log file after every line so the log isn't lost in a crash */
+    if (logfile)
        setbuf(logfile, (char *)NULL);
 #endif
   }

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants