summaryrefslogtreecommitdiffstats
path: root/text-utils/ul.c
diff options
context:
space:
mode:
authorDavidlohr Bueso2010-08-30 04:03:32 +0200
committerKarel Zak2010-09-17 10:02:36 +0200
commit4727b16944cd67f0c9ba1acaba301ac97648a001 (patch)
treee85125dac0a320a485d742c0ae87afd484a4e21b /text-utils/ul.c
parentlscpu: update lscpu.1 to include new additions. (diff)
downloadkernel-qcow2-util-linux-4727b16944cd67f0c9ba1acaba301ac97648a001.tar.gz
kernel-qcow2-util-linux-4727b16944cd67f0c9ba1acaba301ac97648a001.tar.xz
kernel-qcow2-util-linux-4727b16944cd67f0c9ba1acaba301ac97648a001.zip
ul: fix memory leak.
The 'obuf' variable is not being freed after usage and this includes when SIGINTs occur, hence add some basic signal handling. [kzak@redhat.com - remove if-before-free ] Signed-off-by: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'text-utils/ul.c')
-rw-r--r--text-utils/ul.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/text-utils/ul.c b/text-utils/ul.c
index a1491b846..b409c7cd7 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -46,6 +46,7 @@
#include <term.h> /* for setupterm() */
#include <stdlib.h> /* for getenv() */
#include <limits.h> /* for INT_MAX */
+#include <signal.h> /* for signal() */
#include "nls.h"
#include "widechar.h"
@@ -75,6 +76,8 @@ void outc(wint_t c, int width);
void setmode(int newmode);
static void setcol(int newcol);
static void needcol(int col);
+static void exitbuf(void);
+static void sig_handler(int signo);
#define IESC '\033'
#define SO '\016'
@@ -122,6 +125,9 @@ int main(int argc, char **argv)
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+
termtype = getenv("TERM");
if (termtype == NULL || (argv[0][0] == 'c' && !isatty(1)))
termtype = "lpr";
@@ -168,12 +174,16 @@ int main(int argc, char **argv)
f = fopen(argv[optind],"r");
if (f == NULL) {
perror(argv[optind]);
+ exitbuf();
exit(1);
} else
filter(f);
}
- if (ferror(stdout) || fclose(stdout))
+ if (ferror(stdout) || fclose(stdout)) {
+ exitbuf();
return 1;
+ }
+ exitbuf();
return 0;
}
@@ -601,3 +611,14 @@ needcol(int col) {
}
}
}
+
+static void sig_handler(int signo)
+{
+ exitbuf();
+ exit(EXIT_SUCCESS);
+}
+
+static void exitbuf(void)
+{
+ free(obuf);
+}