Fix another decoder mem leak on an error path
authorMatt Caswell <matt@openssl.org>
Thu, 26 May 2022 10:30:09 +0000 (11:30 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 2 Jun 2022 09:31:12 +0000 (10:31 +0100)
If pushing the decoder onto a stack fails then we should free the ref
we just created.

Found due to the error report here:
https://github.com/openssl/openssl/pull/18355#issuecomment-1138205688

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18411)

crypto/encode_decode/decoder_lib.c

index 9dcbab10776bc2e1b7f6c264ce24f18e03fc94ae..8863c316d6ee56847efec3f6cac9adcec38eeaf8 100644 (file)
@@ -362,8 +362,9 @@ static void collect_all_decoders(OSSL_DECODER *decoder, void *arg)
 {
     STACK_OF(OSSL_DECODER) *skdecoders = arg;
 
-    if (OSSL_DECODER_up_ref(decoder))
-        sk_OSSL_DECODER_push(skdecoders, decoder);
+    if (OSSL_DECODER_up_ref(decoder)
+            && !sk_OSSL_DECODER_push(skdecoders, decoder))
+        OSSL_DECODER_free(decoder);
 }
 
 static void collect_extra_decoder(OSSL_DECODER *decoder, void *arg)