c260e0
From ca7b1cd659eb0eb0ef355e3e122742abcea73287 Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Wed, 2 Jul 2014 16:34:48 +0200
c260e0
Subject: [PATCH 1/3] tool: call PR_Cleanup() on exit if NSPR is used
c260e0
c260e0
This prevents valgrind from reporting possibly lost memory that NSPR
c260e0
uses for file descriptor cache and other globally allocated internal
c260e0
data structures.
c260e0
c260e0
Upstream-commit: 24c3cdce88f39731506c287cb276e8bf4a1ce393
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 src/tool_main.c | 10 ++++++++++
c260e0
 1 file changed, 10 insertions(+)
c260e0
c260e0
diff --git a/src/tool_main.c b/src/tool_main.c
c260e0
index 95e9cc7..6a1ed6c 100644
c260e0
--- a/src/tool_main.c
c260e0
+++ b/src/tool_main.c
c260e0
@@ -27,6 +27,10 @@
c260e0
 #include <signal.h>
c260e0
 #endif
c260e0
 
c260e0
+#ifdef USE_NSS
c260e0
+#include <nspr.h>
c260e0
+#endif
c260e0
+
c260e0
 #define ENABLE_CURLX_PRINTF
c260e0
 /* use our own printf() functions */
c260e0
 #include "curlx.h"
c260e0
@@ -104,6 +108,12 @@ int main(int argc, char *argv[])
c260e0
     tool_pressanykey();
c260e0
 #endif
c260e0
 
c260e0
+#ifdef USE_NSS
c260e0
+  if(PR_Initialized())
c260e0
+    /* prevent valgrind from reporting possibly lost memory (fd cache, ...) */
c260e0
+    PR_Cleanup();
c260e0
+#endif
c260e0
+
c260e0
   free_config_fields(&config);
c260e0
 
c260e0
 #ifdef __NOVELL_LIBC__
c260e0
-- 
c260e0
2.1.0
c260e0
c260e0
c260e0
From 295471f8122cf6522c36f8e3588e5b4d15a691ea Mon Sep 17 00:00:00 2001
c260e0
From: Alessandro Ghedini <alessandro@ghedini.me>
c260e0
Date: Thu, 17 Jul 2014 14:37:28 +0200
c260e0
Subject: [PATCH 2/3] build: link curl to NSS libraries when NSS support is
c260e0
 enabled
c260e0
c260e0
This fixes a build failure on Debian caused by commit
c260e0
24c3cdce88f39731506c287cb276e8bf4a1ce393.
c260e0
c260e0
Bug: http://curl.haxx.se/mail/lib-2014-07/0209.html
c260e0
c260e0
Upstream-commit: c6e7cbb94e669b85d3eb8e015ec51d0072112133
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 configure       | 5 ++++-
c260e0
 configure.ac    | 4 ++++
c260e0
 src/Makefile.am | 2 +-
c260e0
 src/Makefile.in | 3 ++-
c260e0
 4 files changed, 11 insertions(+), 3 deletions(-)
c260e0
c260e0
diff --git a/configure b/configure
c260e0
index 8741e21..c5d1817 100755
c260e0
--- a/configure
c260e0
+++ b/configure
c260e0
@@ -913,7 +913,7 @@ LIBMETALINK_LIBS
c260e0
 CURL_CA_BUNDLE
c260e0
 SSL_ENABLED
c260e0
 USE_AXTLS
c260e0
-HAVE_NSS_INITCONTEXT
c260e0
+NSS_LIBS
c260e0
 USE_NSS
c260e0
 USE_CYASSL
c260e0
 USE_POLARSSL
c260e0
@@ -23697,6 +23697,9 @@ fi
c260e0
         { $as_echo "$as_me:${as_lineno-$LINENO}: detected NSS version $version" >&5
c260e0
 $as_echo "$as_me: detected NSS version $version" >&6;}
c260e0
 
c260e0
+                NSS_LIBS=$addlib
c260e0
+
c260e0
+
c260e0
                                         if test "x$cross_compiling" != "xyes"; then
c260e0
           LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$nssprefix/lib$libsuff"
c260e0
           export LD_LIBRARY_PATH
c260e0
diff --git a/configure.ac b/configure.ac
c260e0
index 70ef0b7..60a6b58 100644
c260e0
--- a/configure.ac
c260e0
+++ b/configure.ac
c260e0
@@ -2211,6 +2211,10 @@ if test "$curl_ssl_msg" = "$init_ssl_msg"; then
c260e0
       if test "x$USE_NSS" = "xyes"; then
c260e0
         AC_MSG_NOTICE([detected NSS version $version])
c260e0
 
c260e0
+        dnl needed when linking the curl tool without USE_EXPLICIT_LIB_DEPS
c260e0
+        NSS_LIBS=$addlib
c260e0
+        AC_SUBST([NSS_LIBS])
c260e0
+
c260e0
         dnl when shared libs were found in a path that the run-time
c260e0
         dnl linker doesn't search through, we need to add it to
c260e0
         dnl LD_LIBRARY_PATH to prevent further configure tests to fail
c260e0
diff --git a/src/Makefile.am b/src/Makefile.am
c260e0
index af5a488..6863078 100644
c260e0
--- a/src/Makefile.am
c260e0
+++ b/src/Makefile.am
c260e0
@@ -60,7 +60,7 @@ LIBS = $(BLANK_AT_MAKETIME)
c260e0
 if USE_EXPLICIT_LIB_DEPS
c260e0
 curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @LIBCURL_LIBS@
c260e0
 else
c260e0
-curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@
c260e0
+curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @NSS_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@
c260e0
 endif
c260e0
 
c260e0
 curl_LDFLAGS = @LIBMETALINK_LDFLAGS@
c260e0
diff --git a/src/Makefile.in b/src/Makefile.in
c260e0
index 41fb549..1b578c2 100644
c260e0
--- a/src/Makefile.in
c260e0
+++ b/src/Makefile.in
c260e0
@@ -231,6 +231,7 @@ NMEDIT = @NMEDIT@
c260e0
 # Use the C locale to ensure that only ASCII characters appear in the
c260e0
 # embedded text.
c260e0
 NROFF = env LC_ALL=C @NROFF@ @MANOPT@ # figured out by the configure script
c260e0
+NSS_LIBS = @NSS_LIBS@
c260e0
 OBJDUMP = @OBJDUMP@
c260e0
 OBJEXT = @OBJEXT@
c260e0
 OTOOL = @OTOOL@
c260e0
@@ -463,7 +464,7 @@ CURL_HFILES = \
c260e0
 	tool_xattr.h
c260e0
 
c260e0
 curl_SOURCES = $(CURL_CFILES) $(CURLX_ONES) $(CURL_HFILES)
c260e0
-@USE_EXPLICIT_LIB_DEPS_FALSE@curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@
c260e0
+@USE_EXPLICIT_LIB_DEPS_FALSE@curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @NSS_LIBS@ @ZLIB_LIBS@ @CURL_NETWORK_AND_TIME_LIBS@
c260e0
 @USE_EXPLICIT_LIB_DEPS_TRUE@curl_LDADD = $(top_builddir)/lib/libcurl.la @LIBMETALINK_LIBS@ @LIBCURL_LIBS@
c260e0
 curl_LDFLAGS = @LIBMETALINK_LDFLAGS@
c260e0
 curl_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS)
c260e0
-- 
c260e0
2.1.0
c260e0
c260e0
c260e0
From 0631da3859c9868ff317521544a246b5be83e600 Mon Sep 17 00:00:00 2001
c260e0
From: Kamil Dudka <kdudka@redhat.com>
c260e0
Date: Tue, 14 Jul 2015 17:08:44 +0200
c260e0
Subject: [PATCH 3/3] libtest: call PR_Cleanup() on exit if NSPR is used
c260e0
MIME-Version: 1.0
c260e0
Content-Type: text/plain; charset=UTF-8
c260e0
Content-Transfer-Encoding: 8bit
c260e0
c260e0
This prevents valgrind from reporting possibly lost memory that NSPR
c260e0
uses for file descriptor cache and other globally allocated internal
c260e0
data structures.
c260e0
c260e0
Reported-by: Štefan Kremeň
c260e0
c260e0
Upstream-commit: cd20e81e89ecebc5064e1d3e22e62e2802b2711e
c260e0
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
c260e0
---
c260e0
 tests/libtest/Makefile.am |  4 ++--
c260e0
 tests/libtest/Makefile.in |  4 ++--
c260e0
 tests/libtest/first.c     | 15 ++++++++++++++-
c260e0
 3 files changed, 18 insertions(+), 5 deletions(-)
c260e0
c260e0
diff --git a/tests/libtest/Makefile.am b/tests/libtest/Makefile.am
c260e0
index ba4097f..a844ab2 100644
c260e0
--- a/tests/libtest/Makefile.am
c260e0
+++ b/tests/libtest/Makefile.am
c260e0
@@ -62,8 +62,8 @@ if USE_EXPLICIT_LIB_DEPS
c260e0
 SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@
c260e0
 TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@
c260e0
 else
c260e0
-SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_LIBS@
c260e0
-TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_AND_TIME_LIBS@
c260e0
+SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_LIBS@ @NSS_LIBS@
c260e0
+TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_AND_TIME_LIBS@ @NSS_LIBS@
c260e0
 endif
c260e0
 
c260e0
 # Dependencies (may need to be overriden)
c260e0
diff --git a/tests/libtest/Makefile.in b/tests/libtest/Makefile.in
c260e0
index e6826c0..9086af3 100644
c260e0
--- a/tests/libtest/Makefile.in
c260e0
+++ b/tests/libtest/Makefile.in
c260e0
@@ -949,9 +949,9 @@ AUTOMAKE_OPTIONS = foreign nostdinc
c260e0
 EXTRA_DIST = test75.pl test307.pl test610.pl test613.pl test1013.pl	\
c260e0
 test1022.pl Makefile.inc notexists.pl
c260e0
 
c260e0
-@USE_EXPLICIT_LIB_DEPS_FALSE@SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_LIBS@
c260e0
+@USE_EXPLICIT_LIB_DEPS_FALSE@SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_LIBS@ @NSS_LIBS@
c260e0
 @USE_EXPLICIT_LIB_DEPS_TRUE@SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@
c260e0
-@USE_EXPLICIT_LIB_DEPS_FALSE@TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_AND_TIME_LIBS@
c260e0
+@USE_EXPLICIT_LIB_DEPS_FALSE@TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_AND_TIME_LIBS@ @NSS_LIBS@
c260e0
 @USE_EXPLICIT_LIB_DEPS_TRUE@TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@
c260e0
 
c260e0
 # Dependencies (may need to be overriden)
c260e0
diff --git a/tests/libtest/first.c b/tests/libtest/first.c
c260e0
index 253acb2..94748a5 100644
c260e0
--- a/tests/libtest/first.c
c260e0
+++ b/tests/libtest/first.c
c260e0
@@ -25,6 +25,10 @@
c260e0
 #include <locale.h> /* for setlocale() */
c260e0
 #endif
c260e0
 
c260e0
+#ifdef USE_NSS
c260e0
+#include <nspr.h>
c260e0
+#endif
c260e0
+
c260e0
 #ifdef CURLDEBUG
c260e0
 #  define MEMDEBUG_NODEFINES
c260e0
 #  include "memdebug.h"
c260e0
@@ -97,6 +101,7 @@ static void memory_tracking_init(void)
c260e0
 int main(int argc, char **argv)
c260e0
 {
c260e0
   char *URL;
c260e0
+  int result;
c260e0
 
c260e0
   memory_tracking_init();
c260e0
 
c260e0
@@ -127,5 +132,13 @@ int main(int argc, char **argv)
c260e0
 
c260e0
   fprintf(stderr, "URL: %s\n", URL);
c260e0
 
c260e0
-  return test(URL);
c260e0
+  result = test(URL);
c260e0
+
c260e0
+#ifdef USE_NSS
c260e0
+  if(PR_Initialized())
c260e0
+    /* prevent valgrind from reporting possibly lost memory (fd cache, ...) */
c260e0
+    PR_Cleanup();
c260e0
+#endif
c260e0
+
c260e0
+  return result;
c260e0
 }
c260e0
-- 
c260e0
2.4.3
c260e0