Skip to content

Commit 172eee4

Browse files
committed
pkcs7: fix memory leak in error path of PKCS7.new and .read_smime
A follow-up to commit 27e11f2 and 07eceb7. The PKCS7 object must be freed before raising an exception.
1 parent 07eceb7 commit 172eee4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ext/openssl/ossl_pkcs7.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,10 @@ ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
167167
BIO_free(in);
168168
if (!pkcs7)
169169
ossl_raise(ePKCS7Error, "Could not parse the PKCS7");
170-
if (!pkcs7->d.ptr)
170+
if (!pkcs7->d.ptr) {
171+
PKCS7_free(pkcs7);
171172
ossl_raise(ePKCS7Error, "No content in PKCS7");
173+
}
172174

173175
data = out ? ossl_membio2str(out) : Qnil;
174176
SetPKCS7(ret, pkcs7);
@@ -350,8 +352,10 @@ ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
350352
BIO_free(in);
351353
if (!p7)
352354
ossl_raise(rb_eArgError, "Could not parse the PKCS7");
353-
if (!p7->d.ptr)
355+
if (!p7->d.ptr) {
356+
PKCS7_free(p7);
354357
ossl_raise(rb_eArgError, "No content in PKCS7");
358+
}
355359

356360
RTYPEDDATA_DATA(self) = p7;
357361
PKCS7_free(p7_orig);

0 commit comments

Comments
 (0)