teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone
Blob Blame History Raw
From bc79f3533882dfcffb4dd018e2d1a56691c99248 Mon Sep 17 00:00:00 2001
Message-Id: <bc79f3533882dfcffb4dd018e2d1a56691c99248.1561028242.git.pmatilai@redhat.com>
From: Panu Matilainen <pmatilai@redhat.com>
Date: Thu, 20 Jun 2019 13:50:23 +0300
Subject: [PATCH] Don't hog thread local storage, it's a scarce resource
 (RhBug:1722181)

Commit 6487e873f3169c2bffbd52808b6c749e6c104ff5 introduced a thread local
BUFSIZ static buffer for header format error reporting but thread local
storage is apparently a rather scarce resource (on some architectures
more so than others) and this is highly excessive use of that resource.
Use a thread local pointer to dynamically (re)allocated buffer instead.
---
 lib/headerfmt.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/headerfmt.c b/lib/headerfmt.c
index 1f6390b5e..7c0da1bd9 100644
--- a/lib/headerfmt.c
+++ b/lib/headerfmt.c
@@ -221,18 +221,18 @@ static char * hsaReserve(headerSprintfArgs hsa, size_t need)
 RPM_GNUC_PRINTF(2, 3)
 static void hsaError(headerSprintfArgs hsa, const char *fmt, ...)
 {
-    /* Use thread local static buffer as headerFormat() errmsg arg is const */
-    static __thread char errbuf[BUFSIZ];
+    /* Use thread local buffer as headerFormat() errmsg arg is const */
+    static __thread char *errbuf = NULL;
 
     if (fmt == NULL) {
 	hsa->errmsg = NULL;
     } else {
 	va_list ap;
 
+	free(errbuf);
 	va_start(ap, fmt);
-	vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
+	rvasprintf(&errbuf, fmt, ap);
 	va_end(ap);
-
 	hsa->errmsg = errbuf;
     }
 }
-- 
2.21.0