From: Paul Floyd Date: Sun, 3 Nov 2024 19:42:43 +0000 (+0100) Subject: Bug 494327 - Crash when running Helgrind built with #define TRACE_PTH_FNS 1 X-Git-Tag: VALGRIND_3_25_0~253 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2ef9690458cf472cb8a4da3793657b2c5a8cda6;p=thirdparty%2Fvalgrind.git Bug 494327 - Crash when running Helgrind built with #define TRACE_PTH_FNS 1 Use write() rather than 'fprintf()' for the TRACE_PTH_FNS blocks for pthread_mutex_lock and pthread_mutex_lock. Mixing FILE and fd isn't great, but this is to stderr which gets flushed on every line, and it is only for developer builds that modify that TRACE_PTH_FNS macro. --- diff --git a/NEWS b/NEWS index b0c0b80cf..eb1370da0 100644 --- a/NEWS +++ b/NEWS @@ -23,6 +23,7 @@ bugzilla (https://bugs.kde.org/enter_bug.cgi?product=valgrind) rather than mailing the developers (or mailing lists) directly -- bugs that are not entered into bugzilla tend to get forgotten about or ignored. +494327 Crash when running Helgrind built with #define TRACE_PTH_FNS 1 494337 All threaded applications cause still holding lock errors 495488 Add FreeBSD getrlimitusage syscall wrapper diff --git a/helgrind/hg_intercepts.c b/helgrind/hg_intercepts.c index ba16e33f9..3c6b127ac 100644 --- a/helgrind/hg_intercepts.c +++ b/helgrind/hg_intercepts.c @@ -55,6 +55,8 @@ #include "pub_tool_clreq.h" #include "helgrind.h" #include "config.h" +#include +#include #if defined(VGO_solaris) @@ -974,7 +976,10 @@ static int mutex_lock_WRK(pthread_mutex_t *mutex) OrigFn fn; VALGRIND_GET_ORIG_FN(fn); if (TRACE_PTH_FNS) { - fprintf(stderr, "<< pthread_mxlock %p", mutex); fflush(stderr); + char buf[30]; + snprintf(buf, 30, "<< pthread_mxlock %p", mutex); + write(STDERR_FILENO, buf, strlen(buf)); + fsync(STDERR_FILENO); } #if defined(VGO_freebsd) @@ -1005,7 +1010,9 @@ HG_MUTEX_LOCK_OUT: } if (TRACE_PTH_FNS) { - fprintf(stderr, " :: mxlock -> %d >>\n", ret); + char buf[30]; + snprintf(buf, 30, " :: mxlock -> %d >>\n", ret); + write(STDERR_FILENO, buf, strlen(buf)); } return ret; } @@ -1231,7 +1238,10 @@ static int mutex_unlock_WRK(pthread_mutex_t *mutex) VALGRIND_GET_ORIG_FN(fn); if (TRACE_PTH_FNS) { - fprintf(stderr, "<< pthread_mxunlk %p", mutex); fflush(stderr); + char buf[30]; + snprintf(buf, 30, "<< pthread_mxunlk %p", mutex); + write(STDERR_FILENO, buf, strlen(buf)); + fsync(STDERR_FILENO); } DO_CREQ_v_W(_VG_USERREQ__HG_PTHREAD_MUTEX_UNLOCK_PRE, @@ -1247,7 +1257,9 @@ static int mutex_unlock_WRK(pthread_mutex_t *mutex) } if (TRACE_PTH_FNS) { - fprintf(stderr, " mxunlk -> %d >>\n", ret); + char buf[30]; + snprintf(buf, 30, " :: mxunlk -> %d >>\n", ret); + write(STDERR_FILENO, buf, strlen(buf)); } return ret; }