fix memory management

This commit is contained in:
Jacob Barthelmeh 2017-06-16 11:52:52 -06:00
parent 01cd58cc43
commit 19244fc0c9
3 changed files with 10 additions and 3 deletions

View File

@ -673,7 +673,7 @@ long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **ptr)
return WOLFSSL_FAILURE;
}
if (bio->type == WOLFSSL_BIO_FILE) {
if (bio->type == WOLFSSL_BIO_FILE || bio->type == WOLFSSL_BIO_SOCKET) {
WOLFSSL_MSG("NO memory buffer for FILE type");
return SSL_FAILURE;
}

View File

@ -12198,7 +12198,8 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
XMEMSET(bio, 0, sizeof(WOLFSSL_BIO));
bio->type = method->type;
bio->close = BIO_CLOSE; /* default to close things */
if (method->type != WOLFSSL_BIO_FILE) {
if (method->type != WOLFSSL_BIO_FILE &&
method->type != WOLFSSL_BIO_SOCKET) {
bio->mem_buf =(WOLFSSL_BUF_MEM*)XMALLOC(sizeof(WOLFSSL_BUF_MEM),
0, DYNAMIC_TYPE_OPENSSL);
if (bio->mem_buf == NULL) {
@ -12239,7 +12240,7 @@ int wolfSSL_set_compression(WOLFSSL* ssl)
bio->memLen = bio->wrSz = len;
bio->mem = (byte*)XMALLOC(len, 0, DYNAMIC_TYPE_OPENSSL);
if (bio->mem == NULL) {
XFREE(bio, 0, DYNAMIC_TYPE_OPENSSL);
wolfSSL_BIO_free(bio);
return NULL;
}
if (bio->mem_buf != NULL) {
@ -21136,6 +21137,9 @@ int wolfSSL_RAND_egd(const char* nm)
#endif
if (nm == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
return SSL_FATAL_ERROR;
}

View File

@ -14933,6 +14933,7 @@ static void test_wolfSSL_PEM_read_bio(void)
int bytes;
X509* x509;
BIO* bio = NULL;
BUF_MEM* buf;
printf(testingFmt, "wolfSSL_PEM_read_bio()");
@ -14944,8 +14945,10 @@ static void test_wolfSSL_PEM_read_bio(void)
AssertNotNull(bio = BIO_new_mem_buf((void*)buff, bytes));
AssertNotNull(x509 = PEM_read_bio_X509_AUX(bio, NULL, NULL, NULL));
AssertIntEQ((int)BIO_set_fd(bio, 0, BIO_NOCLOSE), 1);
AssertIntEQ(SSL_SUCCESS, BIO_get_mem_ptr(bio, &buf));
BIO_free(bio);
BUF_MEM_free(buf);
X509_free(x509);
printf(resultFmt, passed);