[CRIU] [PATCHv3 2/2] config: Fix memory initialization

Radostin Stoyanov rstoyanov1 at gmail.com
Thu Jan 24 21:39:24 MSK 2019


On 24/01/2019 17:08, Andrei Vagin wrote:
> On Thu, Jan 24, 2019 at 09:00:46AM -0800, Andrei Vagin wrote:
>> On Tue, Jan 22, 2019 at 09:12:40AM +0000, Radostin Stoyanov wrote:
>>> Initialize allocated memory when parsing configuration file.
>>>
>>> v3: Use calloc() instead of malloc() followed by memset()
>>>
>>> Signed-off-by: Radostin Stoyanov <rstoyanov1 at gmail.com>
>>> ---
>>>  criu/config.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/criu/config.c b/criu/config.c
>>> index 89afdd748..a0bfae10a 100644
>>> --- a/criu/config.c
>>> +++ b/criu/config.c
>>> @@ -54,7 +54,7 @@ static char ** parse_config(char *filepath)
>>>  	if (!configfile) {
>>>  		return NULL;
>>>  	}
>>> -	configuration = xmalloc(config_size * sizeof(char *));
>>> +	configuration = xzalloc(config_size * sizeof(char *));
>> Why does it have to be initialized?

I tried to describe why in
https://lists.openvz.org/pipermail/criu/2019-January/043307.html
but it is a good point that the description should be in the commit message.

> There is  xrealloc, which doesn't initialize memory.
>
> I think you need to set only the last element of this array to NULL.
>
> I don't like a style of this function. I think we need to split it on
> smaller parts and write more comments. We have a lot of if-s there, I
> would like to have a comment before mostly each of them.
I will send a "refactor configuration file parsing" patch in which
we could split the function into smaller parts and add comments.

Radostin


More information about the CRIU mailing list