[CRIU] [PATCHv3 2/2] config: Fix memory initialization
Andrei Vagin
avagin at gmail.com
Thu Jan 24 20:08:06 MSK 2019
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?
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.
Thanks,
AV
>
> > if (configuration == NULL) {
> > fclose(configfile);
> > exit(1);
> > --
> > 2.20.1
> >
> > _______________________________________________
> > CRIU mailing list
> > CRIU at openvz.org
> > https://lists.openvz.org/mailman/listinfo/criu
More information about the CRIU
mailing list