Re: [FFmpeg-devel] [PATCH] hwcontext_vaapi: avoid fd leak in vaapi_device_derive

2020-07-27 Thread Mark Thompson

On 24/07/2020 08:29, Haihao Xiang wrote:

---
  libavutil/hwcontext_vaapi.c | 6 +-
  1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index fb9be19647..a4dfaba92c 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1698,8 +1698,12 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
  #endif
  
  priv = av_mallocz(sizeof(*priv));

-if (!priv)
+if (!priv) {
+/* fd is opened in this function */
+if (fd != src_hwctx->fd)
+close(fd);
  return AVERROR(ENOMEM);
+}
  
  if (fd == src_hwctx->fd) {

  // The fd is inherited from the source context and we are holding


Yep.  Made the comment style consistent with the rest of the file and applied.

Thanks,

- Mark
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

[FFmpeg-devel] [PATCH] hwcontext_vaapi: avoid fd leak in vaapi_device_derive

2020-07-24 Thread Haihao Xiang
---
 libavutil/hwcontext_vaapi.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index fb9be19647..a4dfaba92c 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -1698,8 +1698,12 @@ static int vaapi_device_derive(AVHWDeviceContext *ctx,
 #endif
 
 priv = av_mallocz(sizeof(*priv));
-if (!priv)
+if (!priv) {
+/* fd is opened in this function */
+if (fd != src_hwctx->fd)
+close(fd);
 return AVERROR(ENOMEM);
+}
 
 if (fd == src_hwctx->fd) {
 // The fd is inherited from the source context and we are holding
-- 
2.25.1

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".