summaryrefslogtreecommitdiffstats
path: root/text-utils/rev.c
diff options
context:
space:
mode:
authorSami Kerola2011-04-02 18:11:08 +0200
committerKarel Zak2011-04-06 10:45:02 +0200
commit2226064c52af6ae5d5c8871056aede10a7d14b97 (patch)
tree40b65f1022660ed1f9c3c211ccc4ea5db2ac23bb /text-utils/rev.c
parentrev: use xrealloc from xalloc.h (diff)
downloadkernel-qcow2-util-linux-2226064c52af6ae5d5c8871056aede10a7d14b97.tar.gz
kernel-qcow2-util-linux-2226064c52af6ae5d5c8871056aede10a7d14b97.tar.xz
kernel-qcow2-util-linux-2226064c52af6ae5d5c8871056aede10a7d14b97.zip
rev: memory leak fix
Moving the malloc out of loop will make leak to disappear, and the command might run few jiffie quicker when there are 1+N arguments. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'text-utils/rev.c')
-rw-r--r--text-utils/rev.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/text-utils/rev.c b/text-utils/rev.c
index 31004a070..76a362030 100644
--- a/text-utils/rev.c
+++ b/text-utils/rev.c
@@ -107,6 +107,8 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
+ buf = xmalloc(bufsiz * sizeof(wchar_t));
+
do {
if (*argv) {
if ((fp = fopen(*argv, "r")) == NULL) {
@@ -118,8 +120,6 @@ int main(int argc, char *argv[])
filename = *argv++;
}
- buf = xmalloc(bufsiz * sizeof(wchar_t));
-
while (fgetws(buf, bufsiz, fp)) {
len = wcslen(buf);