aboutsummaryrefslogtreecommitdiff
path: root/options.c
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-10-27 00:30:13 +0200
committerPetr Machata <pmachata@redhat.com>2012-10-27 00:30:13 +0200
commit8a98e6f756c7e6a4171e7dee563f0efbb28b9f33 (patch)
tree4b28d85e5efe25fa1a908ebc3231f14a991d8367 /options.c
parent47d70f6efd145113ad555dd2ba542d1050bbb784 (diff)
downloadltrace-8a98e6f756c7e6a4171e7dee563f0efbb28b9f33.tar.gz
Fix memory handling of -F arguments
This plugs a leak.
Diffstat (limited to 'options.c')
-rw-r--r--options.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/options.c b/options.c
index 66d2332..b0de6f0 100644
--- a/options.c
+++ b/options.c
@@ -513,12 +513,18 @@ process_options(int argc, char **argv)
break;
case 'F':
{
- struct opt_F_t *tmp = malloc(sizeof(struct opt_F_t));
- if (!tmp) {
- perror("ltrace: malloc");
+ struct opt_F_t *tmp = malloc(sizeof(*tmp));
+ if (tmp == NULL) {
+ fail:
+ fprintf(stderr, "%s\n",
+ strerror(errno));
+ free(tmp);
exit(1);
}
tmp->filename = strdup(optarg);
+ if (tmp->filename == NULL)
+ goto fail;
+ tmp->own_filename = 1;
tmp->next = opt_F;
opt_F = tmp;
break;
@@ -625,7 +631,9 @@ process_options(int argc, char **argv)
opt_F->next = malloc(sizeof(struct opt_F_t));
opt_F->next->next = NULL;
opt_F->filename = USER_CONFIG_FILE;
+ opt_F->own_filename = 0;
opt_F->next->filename = SYSTEM_CONFIG_FILE;
+ opt_F->next->own_filename = 0;
}
/* Reverse the config file list since it was built by
* prepending, and it would make more sense to process the