From: Paul F. <pa...@so...> - 2024-11-03 19:45:34
|
https://sourceware.org/git/gitweb.cgi?p=valgrind.git;h=a2ef9690458cf472cb8a4da3793657b2c5a8cda6 commit a2ef9690458cf472cb8a4da3793657b2c5a8cda6 Author: Paul Floyd <pj...@wa...> Date: Sun Nov 3 20:42:43 2024 +0100 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: --- NEWS | 1 + helgrind/hg_intercepts.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index b0c0b80cfa..eb1370da03 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 ba16e33f9b..3c6b127ac9 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 <string.h> +#include <unistd.h> #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; } |