]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 494327 - Crash when running Helgrind built with #define TRACE_PTH_FNS 1
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 3 Nov 2024 19:42:43 +0000 (20:42 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 3 Nov 2024 19:42:43 +0000 (20:42 +0100)
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.

NEWS
helgrind/hg_intercepts.c

diff --git a/NEWS b/NEWS
index b0c0b80cfa6312afd4f69064d87b619770261490..eb1370da03224690b7219713d0bc7d9bff30ab1b 100644 (file)
--- 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
 
index ba16e33f9befd0ff9fcf473db714374a0ffb8bca..3c6b127ac9ef4bfca9307c41d6bcfacd06cfcc40 100644 (file)
@@ -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;
 }