[PATCH] ustream-ssl: openssl: fix bio memory leak

Daniel Golle daniel at makrotopia.org
Tue Dec 8 17:25:41 EST 2020


On Mon, Nov 02, 2020 at 09:53:28AM +0800, serial115200 at outlook.com wrote:
> From: Pan Chen <serial115200 at outlook.com>
> 
> free memory of bio method when ustream be freed

Looked good on the first view, but doesn't compile:
ustream-io-openssl.c: In function 's_ustream_free':
ustream-io-openssl.c:45:17: error: dereferencing pointer to incomplete type 'BIO' {aka 'struct bio_st'}
  BIO_meth_free(b->method);
                   ^~

This is due to type BIO being opaque. We may have to keep a reference
of the ustream method in order to be able to free it.


> 
> Signed-off-by: Pan Chen <serial115200 at outlook.com>
> ---
>  openssl_bio_compat.h | 7 +++++++
>  ustream-io-openssl.c | 1 +
>  2 files changed, 8 insertions(+)
> 
> diff --git a/openssl_bio_compat.h b/openssl_bio_compat.h
> index 9355c86..39a0455 100644
> --- a/openssl_bio_compat.h
> +++ b/openssl_bio_compat.h
> @@ -28,6 +28,13 @@ static inline BIO_METHOD *BIO_meth_new(int type, const char *name)
>  	return bm;
>  }
>  
> +static inline void BIO_meth_free(BIO_METHOD *bm)
> +{
> +	if (bm != NULL) {
> +		free(bm);
> +	}
> +}
> +
>  #endif /* OPENSSL_VERSION_NUMBER */
>  
>  #endif /* OPENSSL_BIO_COMPAT_H */
> diff --git a/ustream-io-openssl.c b/ustream-io-openssl.c
> index 606ed4a..c9d7fae 100644
> --- a/ustream-io-openssl.c
> +++ b/ustream-io-openssl.c
> @@ -42,6 +42,7 @@ s_ustream_free(BIO *b)
>  	BIO_set_data(b, NULL);
>  	BIO_set_init(b, 0);
>  	BIO_clear_flags(b, ~0);
> +	BIO_meth_free(b->method);
>  	return 1;
>  }
>  
> -- 
> 2.24.1.windows.2
> 
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list