]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rev: memory leak fix
authorSami Kerola <kerolasa@iki.fi>
Sat, 2 Apr 2011 16:11:08 +0000 (18:11 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Apr 2011 08:45:02 +0000 (10:45 +0200)
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>
text-utils/rev.c

index 31004a07001f8db0f2534d775461b3713b416651..76a362030b23ef045dded08850afb63dc790bf2a 100644 (file)
@@ -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);