Skip to content

Commit

Permalink
libtest: call PR_Cleanup() on exit if NSPR is used
Browse files Browse the repository at this point in the history
This prevents valgrind from reporting possibly lost memory that NSPR
uses for file descriptor cache and other globally allocated internal
data structures.

Reported-by: Štefan Kremeň
  • Loading branch information
kdudka committed Jul 14, 2015
1 parent 79416fb commit cd20e81
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tests/libtest/Makefile.am
Expand Up @@ -62,8 +62,8 @@ if USE_EXPLICIT_LIB_DEPS
SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@
TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@
else
SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_LIBS@
TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_AND_TIME_LIBS@
SUPPORTFILES_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_LIBS@ @NSS_LIBS@
TESTUTIL_LIBS = $(top_builddir)/lib/libcurl.la @CURL_NETWORK_AND_TIME_LIBS@ @NSS_LIBS@
endif

# Dependencies (may need to be overriden)
Expand Down
15 changes: 14 additions & 1 deletion tests/libtest/first.c
Expand Up @@ -33,6 +33,10 @@
# include <fcntl.h> /* for setmode() */
#endif

#ifdef USE_NSS
#include <nspr.h>
#endif

#ifdef CURLDEBUG
# define MEMDEBUG_NODEFINES
# include "memdebug.h"
Expand Down Expand Up @@ -128,6 +132,7 @@ char *hexdump(unsigned char *buffer, size_t len)
int main(int argc, char **argv)
{
char *URL;
int result;

#ifdef O_BINARY
# ifdef __HIGHC__
Expand Down Expand Up @@ -166,5 +171,13 @@ int main(int argc, char **argv)

fprintf(stderr, "URL: %s\n", URL);

return test(URL);
result = test(URL);

#ifdef USE_NSS
if(PR_Initialized())
/* prevent valgrind from reporting possibly lost memory (fd cache, ...) */
PR_Cleanup();
#endif

return result;
}

0 comments on commit cd20e81

Please sign in to comment.