diff mbox

[FFmpeg-devel] avcodec/libdav1d: reset pool size on allocation failure

Message ID 20190316025545.7520-1-jamrial@gmail.com
State Accepted
Commit 5cd60b6f2ed8a30341e8f98a38858c18505f6f75
Headers show

Commit Message

James Almer March 16, 2019, 2:55 a.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
No testcase for this, just the theoretical scenario where a library user could
flush the decoder after ENOMEM was signaled here, then pass new data where a
frame with the same size as the last successfully allocated one is the first in
line.

 libavcodec/libdav1d.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

James Almer March 19, 2019, 6:19 p.m. UTC | #1
On 3/15/2019 11:55 PM, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> No testcase for this, just the theoretical scenario where a library user could
> flush the decoder after ENOMEM was signaled here, then pass new data where a
> frame with the same size as the last successfully allocated one is the first in
> line.
> 
>  libavcodec/libdav1d.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
> index 8c8584f4e8..d9079cbbef 100644
> --- a/libavcodec/libdav1d.c
> +++ b/libavcodec/libdav1d.c
> @@ -72,8 +72,10 @@ static int libdav1d_picture_allocator(Dav1dPicture *p, void *cookie)
>          av_buffer_pool_uninit(&dav1d->pool);
>          // Use twice the amount of required padding bytes for aligned_ptr below.
>          dav1d->pool = av_buffer_pool_init(ret + DAV1D_PICTURE_ALIGNMENT * 2, NULL);
> -        if (!dav1d->pool)
> +        if (!dav1d->pool) {
> +            dav1d->pool_size = 0;
>              return AVERROR(ENOMEM);
> +        }
>          dav1d->pool_size = ret;
>      }
>      buf = av_buffer_pool_get(dav1d->pool);

Pushed.
diff mbox

Patch

diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 8c8584f4e8..d9079cbbef 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -72,8 +72,10 @@  static int libdav1d_picture_allocator(Dav1dPicture *p, void *cookie)
         av_buffer_pool_uninit(&dav1d->pool);
         // Use twice the amount of required padding bytes for aligned_ptr below.
         dav1d->pool = av_buffer_pool_init(ret + DAV1D_PICTURE_ALIGNMENT * 2, NULL);
-        if (!dav1d->pool)
+        if (!dav1d->pool) {
+            dav1d->pool_size = 0;
             return AVERROR(ENOMEM);
+        }
         dav1d->pool_size = ret;
     }
     buf = av_buffer_pool_get(dav1d->pool);