summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2013-07-14 14:36:42 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2013-07-14 14:36:42 +0000
commit13ed267505dac94f4624a12708d72027329373bf (patch)
treebac91a526627af10567a81953ea4ab10ea8c8e37
parent134de23d282d583796602ff4ccd6ef9c7bfa2f2e (diff)
Fix possible memory/fd leak in the error path.
From David Hill dhill at mindcry.org; ok krw@
-rw-r--r--libexec/ld.so/ldd/ldd.c9
1 files changed, 3 insertions, 6 deletions
diff --git a/libexec/ld.so/ldd/ldd.c b/libexec/ld.so/ldd/ldd.c
index 7d96eccca20..a682ea01e3b 100644
--- a/libexec/ld.so/ldd/ldd.c
+++ b/libexec/ld.so/ldd/ldd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ldd.c,v 1.15 2011/04/29 07:19:19 jmc Exp $ */
+/* $OpenBSD: ldd.c,v 1.16 2013/07/14 14:36:41 jca Exp $ */
/*
* Copyright (c) 2001 Artur Grabowski <art@openbsd.org>
* All rights reserved.
@@ -126,12 +126,14 @@ doit(char *name)
free(phdr);
return 1;
}
+ close(fd);
for (i = 0; i < ehdr.e_phnum; i++)
if (phdr[i].p_type == PT_INTERP) {
interp = 1;
break;
}
+ free(phdr);
if (ehdr.e_type == ET_DYN && !interp) {
printf("%s:\n", name);
@@ -144,14 +146,9 @@ doit(char *name)
printf("%s\n", dlerror());
return 1;
}
- close(fd);
- free(phdr);
return 0;
}
- close(fd);
- free(phdr);
-
if (i == ehdr.e_phnum) {
warnx("%s: not a dynamic executable", name);
return 1;