Skip to content

Commit 51dc3ab

Browse files
Unload error strings in OpenSSL shutdown. (lsh123#292)
1 parent fc25671 commit 51dc3ab

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/openssl/crypto.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <xmlsec/openssl/x509.h>
3535

3636
static int xmlSecOpenSSLErrorsInit (void);
37+
static void xmlSecOpenSSLErrorsShutdown (void);
3738

3839
static xmlSecCryptoDLFunctionsPtr gXmlSecOpenSSLFunctions = NULL;
3940
static xmlChar* gXmlSecOpenSSLTrustedCertsFolder = NULL;
@@ -357,6 +358,7 @@ xmlSecOpenSSLInit (void) {
357358
int
358359
xmlSecOpenSSLShutdown(void) {
359360
xmlSecOpenSSLSetDefaultTrustedCertsFolder(NULL);
361+
xmlSecOpenSSLErrorsShutdown();
360362
return(0);
361363
}
362364

@@ -452,18 +454,21 @@ xmlSecOpenSSLErrorsDefaultCallback(const char* file, int line, const char* func,
452454
reason, msg);
453455
}
454456

457+
#ifndef OPENSSL_IS_BORINGSSL
458+
static ERR_STRING_DATA xmlSecOpenSSLStrReasons[XMLSEC_ERRORS_MAX_NUMBER + 1];
459+
static ERR_STRING_DATA xmlSecOpenSSLStrLib[] = {
460+
{ ERR_PACK(XMLSEC_OPENSSL_ERRORS_LIB,0,0), "xmlsec routines"},
461+
{ 0, NULL}
462+
};
463+
static ERR_STRING_DATA xmlSecOpenSSLStrDefReason[]= {
464+
{ XMLSEC_OPENSSL_ERRORS_LIB, "xmlsec lib"},
465+
{ 0, NULL}
466+
};
467+
#endif /* OPENSSL_IS_BORINGSSL */
468+
455469
static int
456470
xmlSecOpenSSLErrorsInit(void) {
457471
#ifndef OPENSSL_IS_BORINGSSL
458-
static ERR_STRING_DATA xmlSecOpenSSLStrReasons[XMLSEC_ERRORS_MAX_NUMBER + 1];
459-
static ERR_STRING_DATA xmlSecOpenSSLStrLib[]= {
460-
{ ERR_PACK(XMLSEC_OPENSSL_ERRORS_LIB,0,0), "xmlsec routines"},
461-
{ 0, NULL}
462-
};
463-
static ERR_STRING_DATA xmlSecOpenSSLStrDefReason[]= {
464-
{ XMLSEC_OPENSSL_ERRORS_LIB, "xmlsec lib"},
465-
{ 0, NULL}
466-
};
467472
xmlSecSize pos;
468473

469474
/* initialize reasons array */
@@ -473,7 +478,7 @@ xmlSecOpenSSLErrorsInit(void) {
473478
xmlSecOpenSSLStrReasons[pos].string = xmlSecErrorsGetMsg(pos);
474479
}
475480

476-
/* finally load xmlsec strings in OpenSSL */
481+
/* load xmlsec strings in OpenSSL */
477482
ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrLib); /* define xmlsec lib name */
478483
ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrDefReason); /* define default reason */
479484
ERR_load_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrReasons);
@@ -485,6 +490,20 @@ xmlSecOpenSSLErrorsInit(void) {
485490
return(0);
486491
}
487492

493+
494+
static void
495+
xmlSecOpenSSLErrorsShutdown(void) {
496+
/* remove callback */
497+
xmlSecErrorsSetCallback(NULL);
498+
499+
#ifndef OPENSSL_IS_BORINGSSL
500+
/* unload xmlsec strings from OpenSSL */
501+
ERR_unload_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrLib);
502+
ERR_unload_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrDefReason);
503+
ERR_unload_strings(XMLSEC_OPENSSL_ERRORS_LIB, xmlSecOpenSSLStrReasons);
504+
#endif /* OPENSSL_IS_BORINGSSL */
505+
}
506+
488507
/**
489508
* xmlSecOpenSSLSetDefaultTrustedCertsFolder:
490509
* @path: the default trusted certs path.

0 commit comments

Comments
 (0)