Skip to content

Commit 1605d93

Browse files
committed
nss: use PK11_CreateManagedGenericObject() if available
... so that the memory allocated by applications using libcurl does not grow per each TLS connection. Bug: https://bugzilla.redhat.com/1510247 Closes #2297
1 parent b46cfbc commit 1605d93

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

configure.ac

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2483,6 +2483,15 @@ if test -z "$ssl_backends" -o "x$OPT_NSS" != xno; then
24832483
if test "x$USE_NSS" = "xyes"; then
24842484
AC_MSG_NOTICE([detected NSS version $version])
24852485

2486+
dnl PK11_CreateManagedGenericObject() was introduced in NSS 3.34 because
2487+
dnl PK11_DestroyGenericObject() does not release resources allocated by
2488+
dnl PK11_CreateGenericObject() early enough.
2489+
AC_CHECK_FUNC(PK11_CreateManagedGenericObject,
2490+
[
2491+
AC_DEFINE(HAVE_PK11_CREATEMANAGEDGENERICOBJECT, 1,
2492+
[if you have the PK11_CreateManagedGenericObject function])
2493+
])
2494+
24862495
dnl needed when linking the curl tool without USE_EXPLICIT_LIB_DEPS
24872496
NSS_LIBS=$addlib
24882497
AC_SUBST([NSS_LIBS])

lib/vtls/nss.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,17 @@ static CURLcode nss_create_object(struct ssl_connect_data *connssl,
440440
PK11_SETATTRS(attrs, attr_cnt, CKA_TRUST, pval, sizeof(*pval));
441441
}
442442

443-
obj = PK11_CreateGenericObject(slot, attrs, attr_cnt, PR_FALSE);
443+
/* PK11_CreateManagedGenericObject() was introduced in NSS 3.34 because
444+
* PK11_DestroyGenericObject() does not release resources allocated by
445+
* PK11_CreateGenericObject() early enough. */
446+
obj =
447+
#ifdef HAVE_PK11_CREATEMANAGEDGENERICOBJECT
448+
PK11_CreateManagedGenericObject
449+
#else
450+
PK11_CreateGenericObject
451+
#endif
452+
(slot, attrs, attr_cnt, PR_FALSE);
453+
444454
PK11_FreeSlot(slot);
445455
if(!obj)
446456
return result;

0 commit comments

Comments
 (0)