Author: pfg
Date: Wed Jul 13 14:59:17 2016
New Revision: 302771
URL: https://svnweb.freebsd.org/changeset/base/302771

Log:
  mail(1): check for out of memory conditions when calling calloc(3).
  
  Suggested by: oshogbo
  MFC after:    3 days

Modified:
  head/usr.bin/mail/cmd3.c

Modified: head/usr.bin/mail/cmd3.c
==============================================================================
--- head/usr.bin/mail/cmd3.c    Wed Jul 13 14:37:58 2016        (r302770)
+++ head/usr.bin/mail/cmd3.c    Wed Jul 13 14:59:17 2016        (r302771)
@@ -463,7 +463,8 @@ group(char **argv)
        gname = *argv;
        h = hash(gname);
        if ((gh = findgroup(gname)) == NULL) {
-               gh = calloc(1, sizeof(*gh));
+               if ((gh = calloc(1, sizeof(*gh))) == NULL)
+                       err(1, "Out of memory");
                gh->g_name = vcopy(gname);
                gh->g_list = NULL;
                gh->g_link = groups[h];
@@ -477,7 +478,8 @@ group(char **argv)
         */
 
        for (ap = argv+1; *ap != NULL; ap++) {
-               gp = calloc(1, sizeof(*gp));
+               if ((gp = calloc(1, sizeof(*gp))) == NULL)
+                       err(1, "Out of memory");
                gp->ge_name = vcopy(*ap);
                gp->ge_link = gh->g_list;
                gh->g_list = gp;
@@ -702,7 +704,8 @@ alternates(char **namelist)
        }
        if (altnames != 0)
                (void)free(altnames);
-       altnames = calloc((unsigned)c, sizeof(char *));
+       if ((altnames = calloc((unsigned)c, sizeof(char *))) == NULL)
+               err(1, "Out of memory");
        for (ap = namelist, ap2 = altnames; *ap != NULL; ap++, ap2++) {
                cp = calloc((unsigned)strlen(*ap) + 1, sizeof(char));
                strcpy(cp, *ap);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to