[FFmpeg-user] How to correctly free a double-linked list

Ulf Zibis Ulf.Zibis at gmx.de
Sun Jul 7 16:31:06 EEST 2019


Am 07.07.19 um 15:07 schrieb Paul B Mahol:
> On 7/7/19, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
>> Am 07.07.19 um 14:29 schrieb Paul B Mahol:
>>> On 7/7/19, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
>>>> Am 07.07.19 um 13:51 schrieb Paul B Mahol:
>>>>> There is av_calloc, it calls memset for you after allocation
>>>> Thanks for the hint. I now have:
>>>>     if (s->report >= R_SHIFTS) {
>>>>         s->shifts_sums = av_malloc((s->lines + 1) *
>>>> sizeof(*s->shifts_sums));
>>> This above needs to be calloc.
>> Unfortunately this doesn't help. So I ask:
> Maybe:
>
> s->shifts_sums = av_calloc(s->lines + 1, sizeof(**s->shifts_sums));
With this I get "corrupted size vs. prev_size" immediately after start.
IMHO this is completely wrong as "sizeof(**s->shifts_sums)" is
"sizeof(int16_t)" wich is 2.

So it should be "sizeof(*s->shifts_sums)" aka "sizeof(*int16_t)" which is 8.

So please give me a short answer on this ...

>> Isn't this enough initialization? :
>>         for (int l = s->lines; l >= 0; l--)
>>             s->shifts_sums[l] = av_calloc(s->span_r - s->span_l + 1,
>> sizeof(**s->shifts_sums));
>> I don't get, why I first should write NULLs into the elements of
>> s->shifts_sums[l] by help of memset or calloc.

-Ulf


More information about the ffmpeg-user mailing list