Skip to content

Commit

Permalink
ftpd: replace malloc + memset 0 with calloc.
Browse files Browse the repository at this point in the history
It is faster and usually safer.
Use NULL instead of zero for the pointer.
  • Loading branch information
pgiffuni committed Apr 18, 2016
1 parent d5808eb commit 6e4fcca
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions libexec/ftpd/popen.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ ftpd_popen(char *program, char *type)
if (!pids) {
if ((fds = getdtablesize()) <= 0)
return (NULL);
if ((pids = malloc(fds * sizeof(int))) == NULL)
if ((pids = calloc(fds, sizeof(int))) == NULL)
return (NULL);
memset(pids, 0, fds * sizeof(int));
}
if (pipe(pdes) < 0)
return (NULL);
Expand Down Expand Up @@ -185,7 +184,7 @@ ftpd_pclose(FILE *iop)
* pclose returns -1 if stream is not associated with a
* `popened' command, or, if already `pclosed'.
*/
if (pids == 0 || pids[fdes = fileno(iop)] == 0)
if (pids == NULL || pids[fdes = fileno(iop)] == 0)
return (-1);
(void)fclose(iop);
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
Expand Down

0 comments on commit 6e4fcca

Please sign in to comment.