fix crl resource leaks

This commit is contained in:
toddouska 2012-11-27 11:36:36 -08:00
parent f5590f0abd
commit faa7283ff3
3 changed files with 12 additions and 8 deletions

View File

@ -33,7 +33,7 @@
typedef struct CYASSL_CRL CYASSL_CRL; typedef struct CYASSL_CRL CYASSL_CRL;
CYASSL_LOCAL int InitCRL(CYASSL_CRL*, CYASSL_CERT_MANAGER*); CYASSL_LOCAL int InitCRL(CYASSL_CRL*, CYASSL_CERT_MANAGER*);
CYASSL_LOCAL void FreeCRL(CYASSL_CRL*); CYASSL_LOCAL void FreeCRL(CYASSL_CRL*, int dynamic);
CYASSL_LOCAL int LoadCRL(CYASSL_CRL* crl, const char* path, int type, int mon); CYASSL_LOCAL int LoadCRL(CYASSL_CRL* crl, const char* path, int type, int mon);
CYASSL_LOCAL int BufferLoadCRL(CYASSL_CRL*, const byte*, long, int); CYASSL_LOCAL int BufferLoadCRL(CYASSL_CRL*, const byte*, long, int);

View File

@ -90,7 +90,7 @@ static void FreeCRL_Entry(CRL_Entry* crle)
/* Free all CRL resources */ /* Free all CRL resources */
void FreeCRL(CYASSL_CRL* crl) void FreeCRL(CYASSL_CRL* crl, int dynamic)
{ {
CRL_Entry* tmp = crl->crlList; CRL_Entry* tmp = crl->crlList;
@ -116,6 +116,8 @@ void FreeCRL(CYASSL_CRL* crl)
} }
#endif #endif
FreeMutex(&crl->crlLock); FreeMutex(&crl->crlLock);
if (dynamic) /* free self */
XFREE(crl, NULL, DYNAMIC_TYPE_CRL);
} }
@ -295,7 +297,7 @@ static int SwapLists(CYASSL_CRL* crl)
ret = LoadCRL(&tmp, crl->monitors[0].path, SSL_FILETYPE_PEM, 0); ret = LoadCRL(&tmp, crl->monitors[0].path, SSL_FILETYPE_PEM, 0);
if (ret != SSL_SUCCESS) { if (ret != SSL_SUCCESS) {
CYASSL_MSG("PEM LoadCRL on dir change failed"); CYASSL_MSG("PEM LoadCRL on dir change failed");
FreeCRL(&tmp); FreeCRL(&tmp, 0);
return -1; return -1;
} }
} }
@ -304,14 +306,14 @@ static int SwapLists(CYASSL_CRL* crl)
ret = LoadCRL(&tmp, crl->monitors[1].path, SSL_FILETYPE_ASN1, 0); ret = LoadCRL(&tmp, crl->monitors[1].path, SSL_FILETYPE_ASN1, 0);
if (ret != SSL_SUCCESS) { if (ret != SSL_SUCCESS) {
CYASSL_MSG("DER LoadCRL on dir change failed"); CYASSL_MSG("DER LoadCRL on dir change failed");
FreeCRL(&tmp); FreeCRL(&tmp, 0);
return -1; return -1;
} }
} }
if (LockMutex(&crl->crlLock) != 0) { if (LockMutex(&crl->crlLock) != 0) {
CYASSL_MSG("LockMutex failed"); CYASSL_MSG("LockMutex failed");
FreeCRL(&tmp); FreeCRL(&tmp, 0);
return -1; return -1;
} }
@ -323,7 +325,7 @@ static int SwapLists(CYASSL_CRL* crl)
UnLockMutex(&crl->crlLock); UnLockMutex(&crl->crlLock);
FreeCRL(&tmp); FreeCRL(&tmp, 0);
return 0; return 0;
} }
@ -582,6 +584,8 @@ int LoadCRL(CYASSL_CRL* crl, const char* path, int type, int monitor)
} }
} }
closedir(dir);
return ret; return ret;
} }

View File

@ -592,7 +592,7 @@ void CyaSSL_CertManagerFree(CYASSL_CERT_MANAGER* cm)
if (cm) { if (cm) {
#ifdef HAVE_CRL #ifdef HAVE_CRL
if (cm->crl) if (cm->crl)
FreeCRL(cm->crl); FreeCRL(cm->crl, 1);
#endif #endif
FreeSigners(cm->caList, NULL); FreeSigners(cm->caList, NULL);
FreeMutex(&cm->caLock); FreeMutex(&cm->caLock);
@ -1716,7 +1716,7 @@ int CyaSSL_CertManagerEnableCRL(CYASSL_CERT_MANAGER* cm, int options)
if (InitCRL(cm->crl, cm) != 0) { if (InitCRL(cm->crl, cm) != 0) {
CYASSL_MSG("Init CRL failed"); CYASSL_MSG("Init CRL failed");
FreeCRL(cm->crl); FreeCRL(cm->crl, 1);
cm->crl = NULL; cm->crl = NULL;
return SSL_FAILURE; return SSL_FAILURE;
} }