Browse Source

Fixed memory leaks which would occur if the second of two memory

allocations fails.
looks right deraadt, krw
ok henning
OPENBSD_4_6
tobias 15 years ago
parent
commit
1a4725225f
1 changed files with 7 additions and 3 deletions
  1. +7
    -3
      src/usr.sbin/ntpd/parse.y

+ 7
- 3
src/usr.sbin/ntpd/parse.y View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.45 2008/10/17 14:32:47 henning Exp $ */
/* $OpenBSD: parse.y,v 1.46 2009/03/31 21:03:48 tobias Exp $ */
/* /*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -559,11 +559,15 @@ pushfile(const char *name)
{ {
struct file *nfile; struct file *nfile;
if ((nfile = calloc(1, sizeof(struct file))) == NULL ||
(nfile->name = strdup(name)) == NULL) {
if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
log_warn("malloc"); log_warn("malloc");
return (NULL); return (NULL);
} }
if ((nfile->name = strdup(name)) == NULL) {
log_warn("malloc");
free(nfile);
return (NULL);
}
if ((nfile->stream = fopen(nfile->name, "r")) == NULL) { if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
log_warn("%s", nfile->name); log_warn("%s", nfile->name);
free(nfile->name); free(nfile->name);


Loading…
Cancel
Save