On Tue, Apr 22, 2014 at 03:58:23PM -0400, [email protected] wrote:
> Hi,
>
> Another replacement of malloc & memset with calloc. This time in init.c.
> Also added a check as non existed prior to this.
>
> Index: init.c
> ===================================================================
> RCS file: /cvs/src/sbin/init/init.c,v
> retrieving revision 1.49
> diff -u -p -u -r1.49 init.c
> --- init.c 3 Jan 2014 22:29:00 -0000 1.49
> +++ init.c 22 Apr 2014 19:56:27 -0000
> @@ -860,8 +860,11 @@ new_session(session_t *sprev, int sessio
> typ->ty_getty == 0)
> return (0);
>
> - sp = (session_t *) malloc(sizeof (session_t));
> - memset(sp, 0, sizeof *sp);
> + sp = calloc(1, sizeof (session_t));
> + if (sp == NULL) {
> + err(1, "calloc");
The err(), verr(), errx(), and verrx() functions do not return, but exit
with the value of the argument eval.
A library generally shouldn't exit.
> + return (0);
> + }
>
> sp->se_flags = SE_PRESENT;
> sp->se_index = session_index;