diff --git a/wolfcrypt/src/pkcs12.c b/wolfcrypt/src/pkcs12.c index 399b2a7ad..c221f7b22 100644 --- a/wolfcrypt/src/pkcs12.c +++ b/wolfcrypt/src/pkcs12.c @@ -784,9 +784,6 @@ int wc_i2d_PKCS12(WC_PKCS12* pkcs12, byte** der, int* derSz) if (*der == NULL) { /* Allocate if requested */ buf = (byte*)XMALLOC(totalSz, NULL, DYNAMIC_TYPE_PKCS); - if (buf == NULL) { - ret = MEMORY_E; - } } else { buf = *der; @@ -802,6 +799,10 @@ int wc_i2d_PKCS12(WC_PKCS12* pkcs12, byte** der, int* derSz) } } + if (buf == NULL) { + ret = MEMORY_E; + } + if (ret == 0) { idx = 0;