diff mbox

[FFmpeg-devel,v2] avformat/options: don't call avformat_free_context() within avformat_alloc_context()

Message ID 20191019171805.2670-1-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer Oct. 19, 2019, 5:18 p.m. UTC
avformat_free_context() expects AVFormatContext->internal to not be NULL.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/options.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Andreas Rheinhardt Oct. 19, 2019, 11:42 p.m. UTC | #1
James Almer:
> avformat_free_context() expects AVFormatContext->internal to not be NULL.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  libavformat/options.c | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/libavformat/options.c b/libavformat/options.c
> index c188c23506..756f4d53c5 100644
> --- a/libavformat/options.c
> +++ b/libavformat/options.c
> @@ -144,15 +144,17 @@ static void avformat_get_context_defaults(AVFormatContext *s)
>  AVFormatContext *avformat_alloc_context(void)
>  {
>      AVFormatContext *ic;
> +    AVFormatInternal *internal;
>      ic = av_malloc(sizeof(AVFormatContext));
>      if (!ic) return ic;
> -    avformat_get_context_defaults(ic);
>  
> -    ic->internal = av_mallocz(sizeof(*ic->internal));
> -    if (!ic->internal) {
> -        avformat_free_context(ic);
> +    internal = av_mallocz(sizeof(AVFormatInternal));
> +    if (!internal) {
> +        av_free(ic);
>          return NULL;
>      }
> +    avformat_get_context_defaults(ic);
> +    ic->internal = internal;
>      ic->internal->offset = AV_NOPTS_VALUE;
>      ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
>      ic->internal->shortest_end = AV_NOPTS_VALUE;
> 
Isn't it better (more auto-like) to use sizeof(*internal)? Apart from
that: LGTM.

- Andreas
James Almer Oct. 20, 2019, 12:35 a.m. UTC | #2
On 10/19/2019 8:42 PM, Andreas Rheinhardt wrote:
> James Almer:
>> avformat_free_context() expects AVFormatContext->internal to not be NULL.
>>
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>>  libavformat/options.c | 10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/libavformat/options.c b/libavformat/options.c
>> index c188c23506..756f4d53c5 100644
>> --- a/libavformat/options.c
>> +++ b/libavformat/options.c
>> @@ -144,15 +144,17 @@ static void avformat_get_context_defaults(AVFormatContext *s)
>>  AVFormatContext *avformat_alloc_context(void)
>>  {
>>      AVFormatContext *ic;
>> +    AVFormatInternal *internal;
>>      ic = av_malloc(sizeof(AVFormatContext));
>>      if (!ic) return ic;
>> -    avformat_get_context_defaults(ic);
>>  
>> -    ic->internal = av_mallocz(sizeof(*ic->internal));
>> -    if (!ic->internal) {
>> -        avformat_free_context(ic);
>> +    internal = av_mallocz(sizeof(AVFormatInternal));
>> +    if (!internal) {
>> +        av_free(ic);
>>          return NULL;
>>      }
>> +    avformat_get_context_defaults(ic);
>> +    ic->internal = internal;
>>      ic->internal->offset = AV_NOPTS_VALUE;
>>      ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
>>      ic->internal->shortest_end = AV_NOPTS_VALUE;
>>
> Isn't it better (more auto-like) to use sizeof(*internal)? Apart from
> that: LGTM.

Yes, but i figured I'd mimic the ic malloc above.

Changed and pushed. Thanks.
diff mbox

Patch

diff --git a/libavformat/options.c b/libavformat/options.c
index c188c23506..756f4d53c5 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -144,15 +144,17 @@  static void avformat_get_context_defaults(AVFormatContext *s)
 AVFormatContext *avformat_alloc_context(void)
 {
     AVFormatContext *ic;
+    AVFormatInternal *internal;
     ic = av_malloc(sizeof(AVFormatContext));
     if (!ic) return ic;
-    avformat_get_context_defaults(ic);
 
-    ic->internal = av_mallocz(sizeof(*ic->internal));
-    if (!ic->internal) {
-        avformat_free_context(ic);
+    internal = av_mallocz(sizeof(AVFormatInternal));
+    if (!internal) {
+        av_free(ic);
         return NULL;
     }
+    avformat_get_context_defaults(ic);
+    ic->internal = internal;
     ic->internal->offset = AV_NOPTS_VALUE;
     ic->internal->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE;
     ic->internal->shortest_end = AV_NOPTS_VALUE;