Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
e923a359
Commit
e923a359
authored
Apr 05, 2020
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pthread_frame: make sure ff_thread_release_buffer always cleans the frame
parent
917d28d5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
pthread_frame.c
libavcodec/pthread_frame.c
+20
-4
No files found.
libavcodec/pthread_frame.c
View file @
e923a359
...
@@ -982,10 +982,11 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
...
@@ -982,10 +982,11 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
PerThreadContext
*
p
=
avctx
->
internal
->
thread_ctx
;
PerThreadContext
*
p
=
avctx
->
internal
->
thread_ctx
;
FrameThreadContext
*
fctx
;
FrameThreadContext
*
fctx
;
AVFrame
*
dst
,
*
tmp
;
AVFrame
*
dst
,
*
tmp
;
int
ret
=
0
;
int
can_direct_free
=
!
(
avctx
->
active_thread_type
&
FF_THREAD_FRAME
)
||
int
can_direct_free
=
!
(
avctx
->
active_thread_type
&
FF_THREAD_FRAME
)
||
THREAD_SAFE_CALLBACKS
(
avctx
);
THREAD_SAFE_CALLBACKS
(
avctx
);
if
(
!
f
->
f
||
!
f
->
f
->
buf
[
0
]
)
if
(
!
f
->
f
)
return
;
return
;
if
(
avctx
->
debug
&
FF_DEBUG_BUFFERS
)
if
(
avctx
->
debug
&
FF_DEBUG_BUFFERS
)
...
@@ -994,7 +995,8 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
...
@@ -994,7 +995,8 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
av_buffer_unref
(
&
f
->
progress
);
av_buffer_unref
(
&
f
->
progress
);
f
->
owner
[
0
]
=
f
->
owner
[
1
]
=
NULL
;
f
->
owner
[
0
]
=
f
->
owner
[
1
]
=
NULL
;
if
(
can_direct_free
)
{
// when the frame buffers are not allocated, just reset it to clean state
if
(
can_direct_free
||
!
f
->
f
->
buf
[
0
])
{
av_frame_unref
(
f
->
f
);
av_frame_unref
(
f
->
f
);
return
;
return
;
}
}
...
@@ -1002,13 +1004,17 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
...
@@ -1002,13 +1004,17 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
fctx
=
p
->
parent
;
fctx
=
p
->
parent
;
pthread_mutex_lock
(
&
fctx
->
buffer_mutex
);
pthread_mutex_lock
(
&
fctx
->
buffer_mutex
);
if
(
p
->
num_released_buffers
+
1
>=
INT_MAX
/
sizeof
(
*
p
->
released_buffers
))
if
(
p
->
num_released_buffers
+
1
>=
INT_MAX
/
sizeof
(
*
p
->
released_buffers
))
{
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
goto
fail
;
}
tmp
=
av_fast_realloc
(
p
->
released_buffers
,
&
p
->
released_buffers_allocated
,
tmp
=
av_fast_realloc
(
p
->
released_buffers
,
&
p
->
released_buffers_allocated
,
(
p
->
num_released_buffers
+
1
)
*
(
p
->
num_released_buffers
+
1
)
*
sizeof
(
*
p
->
released_buffers
));
sizeof
(
*
p
->
released_buffers
));
if
(
!
tmp
)
if
(
!
tmp
)
{
ret
=
AVERROR
(
ENOMEM
);
goto
fail
;
goto
fail
;
}
p
->
released_buffers
=
tmp
;
p
->
released_buffers
=
tmp
;
dst
=
&
p
->
released_buffers
[
p
->
num_released_buffers
];
dst
=
&
p
->
released_buffers
[
p
->
num_released_buffers
];
...
@@ -1018,4 +1024,14 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
...
@@ -1018,4 +1024,14 @@ void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
fail:
fail:
pthread_mutex_unlock
(
&
fctx
->
buffer_mutex
);
pthread_mutex_unlock
(
&
fctx
->
buffer_mutex
);
// make sure the frame is clean even if we fail to free it
// this leaks, but it is better than crashing
if
(
ret
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Could not queue a frame for freeing, this will leak
\n
"
);
memset
(
f
->
f
->
buf
,
0
,
sizeof
(
f
->
f
->
buf
));
if
(
f
->
f
->
extended_buf
)
memset
(
f
->
f
->
extended_buf
,
0
,
f
->
f
->
nb_extended_buf
*
sizeof
(
*
f
->
f
->
extended_buf
));
av_frame_unref
(
f
->
f
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment