On 02. 01. 2025. 15:18, Ilia Shipitsin wrote:
> This defect was found by the coccinelle script "unchecked-strdup.cocci".
> It can be backported to all supported branches.

Hello Ilia,

due to allocating memory for list elements, in case of impossibility of memory
allocation, the previously added list elements should be removed and the
memory occupied by them should be deallocated.

Because of that I think the second part of the patch is not good enough and
I'm not sure that it contributes to the quality of the code.

Of course, the code checks if the memory is allocated, so it might prevent a
segmentation fault at some point, but it won't prevent a memory leak.

>       while (*(args[cur_arg])) {
>               name = calloc(1, sizeof(*name));
>               name->name = strdup(args[cur_arg]);
> +             if (name->name == NULL) {
> +                     memprintf(err,"Out of memory.");
> +                     goto fail_free_name;
> +             }
>               LIST_APPEND(&global_51degrees.property_names, &name->list);
>               ++cur_arg;
>       }
>  
>       return 0;
> +
> +fail_free_name:
> +     free(name);
> +fail:
> +     return -1;


Best regards,

-- 
Miroslav Zagorac

What can change the nature of a man?


Reply via email to