summaryrefslogtreecommitdiffstats
path: root/text-utils
diff options
context:
space:
mode:
authorOndrej Oprala2013-09-23 15:39:38 +0200
committerKarel Zak2013-11-08 14:16:29 +0100
commitd2740b0ef6c8b7785f575432fb3ae78cdae8f89e (patch)
treec65ba7029a49d819911ceedb0e15d258e4a1d71a /text-utils
parenthexdump: make addfile() variable names more hinting of their purpose (diff)
downloadkernel-qcow2-util-linux-d2740b0ef6c8b7785f575432fb3ae78cdae8f89e.tar.gz
kernel-qcow2-util-linux-d2740b0ef6c8b7785f575432fb3ae78cdae8f89e.tar.xz
kernel-qcow2-util-linux-d2740b0ef6c8b7785f575432fb3ae78cdae8f89e.zip
hexdump: catch memory leaks
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Diffstat (limited to 'text-utils')
-rw-r--r--text-utils/display.c10
-rw-r--r--text-utils/hexdump.c24
-rw-r--r--text-utils/parse.c2
3 files changed, 32 insertions, 4 deletions
diff --git a/text-utils/display.c b/text-utils/display.c
index 0782c9c12..b6b1f140d 100644
--- a/text-utils/display.c
+++ b/text-utils/display.c
@@ -279,12 +279,12 @@ get(void)
*/
if (!length || (ateof && !next(NULL))) {
if (need == blocksize)
- return(NULL);
+ goto retnul;
if (!need && vflag != ALL &&
!memcmp(curp, savp, nread)) {
if (vflag != DUP)
printf("*\n");
- return(NULL);
+ goto retnul;
}
if (need > 0)
memset((char *)curp + nread, 0, need);
@@ -293,7 +293,7 @@ get(void)
}
if (fileno(stdin) == -1) {
warnx(_("all input file arguments failed"));
- return(NULL);
+ goto retnul;
}
n = fread((char *)curp + nread, sizeof(unsigned char),
length == -1 ? need : min(length, need), stdin);
@@ -323,6 +323,10 @@ get(void)
else
nread += n;
}
+retnul:
+ free (curp);
+ free (savp);
+ return NULL;
}
int next(char **argv)
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 47853a882..8c9b119b9 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -50,6 +50,7 @@ struct list_head fshead; /* head of format strings */
ssize_t blocksize; /* data block size */
int exitval; /* final exit value */
ssize_t length = -1; /* max bytes to read */
+void hex_free(void);
int main(int argc, char **argv)
{
@@ -83,5 +84,28 @@ int main(int argc, char **argv)
next(argv);
display();
+ hex_free();
return exitval;
}
+
+void hex_free(void)
+{
+ struct list_head *p, *pn, *q, *qn, *r, *rn;
+ FS *fs;
+ FU *fu;
+ PR *pr;
+ list_for_each_safe(p, pn, &fshead) {
+ fs = list_entry(p, FS, fslist);
+ list_for_each_safe(q, qn, &fs->fulist) {
+ fu = list_entry(q, FU, fulist);
+ list_for_each_safe(r, rn, &fu->prlist) {
+ pr = list_entry(r, PR, prlist);
+ free(pr->fmt);
+ free(pr);
+ }
+ free(fu->fmt);
+ free(fu);
+ }
+ free(fs);
+ }
+}
diff --git a/text-utils/parse.c b/text-utils/parse.c
index 7454fe15d..37d2a4c86 100644
--- a/text-utils/parse.c
+++ b/text-utils/parse.c
@@ -231,7 +231,7 @@ void rewrite(FS *fs)
/* Only text in the string. */
if (!*p1) {
- pr->fmt = fmtp;
+ pr->fmt = xstrdup(fmtp);
pr->flags = F_TEXT;
break;
}