Blame SOURCES/0057-curl-7.29.0-nss-obj-leak.patch

6311d4
From 543ba995e5beb83a754a8f844491446747c83572 Mon Sep 17 00:00:00 2001
6311d4
From: Kamil Dudka <kdudka@redhat.com>
6311d4
Date: Thu, 8 Feb 2018 11:23:49 +0100
6311d4
Subject: [PATCH] nss: use PK11_CreateManagedGenericObject() if available
6311d4
6311d4
... so that the memory allocated by applications using libcurl does not
6311d4
grow per each TLS connection.
6311d4
6311d4
Bug: https://bugzilla.redhat.com/1510247
6311d4
6311d4
Closes #2297
6311d4
6311d4
Upstream-commit: 1605d93a7b8ac4b7f348e304e018e9d15ffaabf0
6311d4
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
6311d4
---
6311d4
 configure            | 10 ++++++++++
6311d4
 configure.ac         |  9 +++++++++
6311d4
 lib/curl_config.h.in |  3 +++
6311d4
 lib/nss.c            | 12 +++++++++++-
6311d4
 4 files changed, 33 insertions(+), 1 deletion(-)
6311d4
6311d4
diff --git a/configure b/configure
6311d4
index fc260ee..3c77748 100755
6311d4
--- a/configure
6311d4
+++ b/configure
6311d4
@@ -23753,6 +23753,16 @@ $as_echo "$as_me: detected NSS version $version" >&6;}
6311d4
                 NSS_LIBS=$addlib
6311d4
 
6311d4
 
6311d4
+                                ac_fn_c_check_func "$LINENO" "PK11_CreateManagedGenericObject" "ac_cv_func_PK11_CreateManagedGenericObject"
6311d4
+if test "x$ac_cv_func_PK11_CreateManagedGenericObject" = xyes; then :
6311d4
+
6311d4
+
6311d4
+$as_echo "#define HAVE_PK11_CREATEMANAGEDGENERICOBJECT 1" >>confdefs.h
6311d4
+
6311d4
+
6311d4
+fi
6311d4
+
6311d4
+
6311d4
                                         if test "x$cross_compiling" != "xyes"; then
6311d4
           LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$nssprefix/lib$libsuff"
6311d4
           export LD_LIBRARY_PATH
6311d4
diff --git a/configure.ac b/configure.ac
6311d4
index 9612c2f..887ded9 100644
6311d4
--- a/configure.ac
6311d4
+++ b/configure.ac
6311d4
@@ -2216,6 +2216,15 @@ if test "$curl_ssl_msg" = "$init_ssl_msg"; then
6311d4
         NSS_LIBS=$addlib
6311d4
         AC_SUBST([NSS_LIBS])
6311d4
 
6311d4
+        dnl PK11_CreateManagedGenericObject() was introduced in NSS 3.34 because
6311d4
+        dnl PK11_DestroyGenericObject() does not release resources allocated by
6311d4
+        dnl PK11_CreateGenericObject() early enough.
6311d4
+        AC_CHECK_FUNC(PK11_CreateManagedGenericObject,
6311d4
+          [
6311d4
+            AC_DEFINE(HAVE_PK11_CREATEMANAGEDGENERICOBJECT, 1,
6311d4
+                      [if you have the PK11_CreateManagedGenericObject function])
6311d4
+          ])
6311d4
+
6311d4
         dnl when shared libs were found in a path that the run-time
6311d4
         dnl linker doesn't search through, we need to add it to
6311d4
         dnl LD_LIBRARY_PATH to prevent further configure tests to fail
6311d4
diff --git a/lib/curl_config.h.in b/lib/curl_config.h.in
6311d4
index 19b66fa..9db354b 100644
6311d4
--- a/lib/curl_config.h.in
6311d4
+++ b/lib/curl_config.h.in
6311d4
@@ -503,6 +503,9 @@
6311d4
 /* Define to 1 if you have the `pipe' function. */
6311d4
 #undef HAVE_PIPE
6311d4
 
6311d4
+/* if you have the PK11_CreateManagedGenericObject function */
6311d4
+#undef HAVE_PK11_CREATEMANAGEDGENERICOBJECT
6311d4
+
6311d4
 /* Define to 1 if you have a working poll function. */
6311d4
 #undef HAVE_POLL
6311d4
 
6311d4
diff --git a/lib/nss.c b/lib/nss.c
6311d4
index 1b8abd3..31e5d75 100644
6311d4
--- a/lib/nss.c
6311d4
+++ b/lib/nss.c
6311d4
@@ -399,7 +399,17 @@ static CURLcode nss_create_object(struct ssl_connect_data *ssl,
6311d4
     PK11_SETATTRS(attrs, attr_cnt, CKA_TRUST, pval, sizeof(*pval));
6311d4
   }
6311d4
 
6311d4
-  obj = PK11_CreateGenericObject(slot, attrs, attr_cnt, PR_FALSE);
6311d4
+  /* PK11_CreateManagedGenericObject() was introduced in NSS 3.34 because
6311d4
+   * PK11_DestroyGenericObject() does not release resources allocated by
6311d4
+   * PK11_CreateGenericObject() early enough.  */
6311d4
+  obj =
6311d4
+#ifdef HAVE_PK11_CREATEMANAGEDGENERICOBJECT
6311d4
+    PK11_CreateManagedGenericObject
6311d4
+#else
6311d4
+    PK11_CreateGenericObject
6311d4
+#endif
6311d4
+    (slot, attrs, attr_cnt, PR_FALSE);
6311d4
+
6311d4
   PK11_FreeSlot(slot);
6311d4
   if(!obj)
6311d4
     return err;
6311d4
-- 
6311d4
2.13.6
6311d4