Skip to content

Commit 1e9cfeb

Browse files
authored
Merge pull request #1010 from ndossche/clesss-2
Fix memory leak if ossl_bn_new() fails
2 parents 1c4bfef + 309c55d commit 1e9cfeb

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

ext/openssl/ossl_asn1.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,17 @@ asn1integer_to_num(const ASN1_INTEGER *ai)
130130
if (!ai) {
131131
ossl_raise(rb_eTypeError, "ASN1_INTEGER is NULL!");
132132
}
133+
134+
num = ossl_bn_new(BN_value_one());
135+
bn = GetBNPtr(num);
136+
133137
if (ASN1_STRING_type(ai) == V_ASN1_ENUMERATED)
134-
bn = ASN1_ENUMERATED_to_BN(ai, NULL);
138+
bn = ASN1_ENUMERATED_to_BN(ai, bn);
135139
else
136-
bn = ASN1_INTEGER_to_BN(ai, NULL);
140+
bn = ASN1_INTEGER_to_BN(ai, bn);
137141

138142
if (!bn)
139143
ossl_raise(eOSSLError, NULL);
140-
num = ossl_bn_new(bn);
141-
BN_free(bn);
142144

143145
return num;
144146
}

0 commit comments

Comments
 (0)