[sheepdog] [PATCH]Check malloc error for collie

Hitoshi Mitake mitake.hitoshi at gmail.com
Mon Feb 18 02:55:05 CET 2013


At Mon, 18 Feb 2013 09:10:06 +0900,
MORITA Kazutaka wrote:
> 
> At Thu, 14 Feb 2013 23:03:57 +0800,
> harryxiyou at gmail.com wrote:
> >  
> >  static const struct subcommand *find_subcmd(const char *cmd, const char *subcmd)
> > @@ -322,7 +326,11 @@ int main(int argc, char **argv)
> >  	char *p;
> >  	const struct sd_option *sd_opts;
> >  
> > -	init_commands(&commands);
> > +	ret = init_commands(&commands);
> > +	if (ret < 0) {
> > +		fprintf(stderr, "Failed to init commands.\n");
> > +		exit(EXIT_SYSFAIL);
> > +	}
> 
> Since the program exits either way, how about using xmalloc as we do
> in other places?
> 

In this case, I think using malloc() and checking its return value
would be more helpful for collie. Because xmalloc() dies with abort()
when its allocation fails and abort() sets a return value to 134 in a
default behaviour. collie should return values in include/exits.h with
exit() because it can be called from shell scripts.

Or should collie catch SIGABRT and call exit() in the handler?

Thanks,
Hitoshi



More information about the sheepdog mailing list