teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0001-Don-t-hog-thread-local-storage-it-s-a-scarce-resourc.patch

Panu Matilainen 894aa7
From bc79f3533882dfcffb4dd018e2d1a56691c99248 Mon Sep 17 00:00:00 2001
Panu Matilainen 894aa7
Message-Id: <bc79f3533882dfcffb4dd018e2d1a56691c99248.1561028242.git.pmatilai@redhat.com>
Panu Matilainen 894aa7
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 894aa7
Date: Thu, 20 Jun 2019 13:50:23 +0300
Panu Matilainen 894aa7
Subject: [PATCH] Don't hog thread local storage, it's a scarce resource
Panu Matilainen 894aa7
 (RhBug:1722181)
Panu Matilainen 894aa7
Panu Matilainen 894aa7
Commit 6487e873f3169c2bffbd52808b6c749e6c104ff5 introduced a thread local
Panu Matilainen 894aa7
BUFSIZ static buffer for header format error reporting but thread local
Panu Matilainen 894aa7
storage is apparently a rather scarce resource (on some architectures
Panu Matilainen 894aa7
more so than others) and this is highly excessive use of that resource.
Panu Matilainen 894aa7
Use a thread local pointer to dynamically (re)allocated buffer instead.
Panu Matilainen 894aa7
---
Panu Matilainen 894aa7
 lib/headerfmt.c | 8 ++++----
Panu Matilainen 894aa7
 1 file changed, 4 insertions(+), 4 deletions(-)
Panu Matilainen 894aa7
Panu Matilainen 894aa7
diff --git a/lib/headerfmt.c b/lib/headerfmt.c
Panu Matilainen 894aa7
index 1f6390b5e..7c0da1bd9 100644
Panu Matilainen 894aa7
--- a/lib/headerfmt.c
Panu Matilainen 894aa7
+++ b/lib/headerfmt.c
Panu Matilainen 894aa7
@@ -221,18 +221,18 @@ static char * hsaReserve(headerSprintfArgs hsa, size_t need)
Panu Matilainen 894aa7
 RPM_GNUC_PRINTF(2, 3)
Panu Matilainen 894aa7
 static void hsaError(headerSprintfArgs hsa, const char *fmt, ...)
Panu Matilainen 894aa7
 {
Panu Matilainen 894aa7
-    /* Use thread local static buffer as headerFormat() errmsg arg is const */
Panu Matilainen 894aa7
-    static __thread char errbuf[BUFSIZ];
Panu Matilainen 894aa7
+    /* Use thread local buffer as headerFormat() errmsg arg is const */
Panu Matilainen 894aa7
+    static __thread char *errbuf = NULL;
Panu Matilainen 894aa7
 
Panu Matilainen 894aa7
     if (fmt == NULL) {
Panu Matilainen 894aa7
 	hsa->errmsg = NULL;
Panu Matilainen 894aa7
     } else {
Panu Matilainen 894aa7
 	va_list ap;
Panu Matilainen 894aa7
 
Panu Matilainen 894aa7
+	free(errbuf);
Panu Matilainen 894aa7
 	va_start(ap, fmt);
Panu Matilainen 894aa7
-	vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
Panu Matilainen 894aa7
+	rvasprintf(&errbuf, fmt, ap);
Panu Matilainen 894aa7
 	va_end(ap);
Panu Matilainen 894aa7
-
Panu Matilainen 894aa7
 	hsa->errmsg = errbuf;
Panu Matilainen 894aa7
     }
Panu Matilainen 894aa7
 }
Panu Matilainen 894aa7
-- 
Panu Matilainen 894aa7
2.21.0
Panu Matilainen 894aa7