summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-11-13 16:45:44 +0100
committerJiri Olsa <Jiri Olsa jolsa@redhat.com>2011-11-13 16:45:44 +0100
commita9d14bd39501e5a46e8c8a66f511a749cf14a172 (patch)
tree620591119bb7c80bba63d94cb4b3917a4bd27c96
parent09458f02f84fda018378952eecbb051ee5666d80 (diff)
downloadlatrace-error_simulation1.tar.gz
latrace-error_simulation1.tar.xz
latrace-error_simulation1.zip
run: Fix leak in thread structure and fifo descriptor releaseerror_simulation1
-rw-r--r--src/run.c19
-rw-r--r--src/thread.c3
2 files changed, 20 insertions, 2 deletions
diff --git a/src/run.c b/src/run.c
index eb3fb8b..d3f1826 100644
--- a/src/run.c
+++ b/src/run.c
@@ -180,6 +180,21 @@ static int process_fifo(struct lt_config_app *cfg, struct lt_thread *t)
return 0;
}
+static void cleanup_threads(struct lt_config_app *cfg)
+{
+ struct lt_thread *t = cfg->threads;
+
+ while(t) {
+ struct lt_thread *tn;
+
+ close(t->fifo_fd);
+ tn = t->next;
+ free(t);
+ t = tn;
+ }
+ cfg->threads = NULL;
+}
+
static int process(struct lt_config_app *cfg, struct lt_process_args *pa)
{
int finish = 0, getin = 1, status;
@@ -239,7 +254,7 @@ if (ret < 0) \
if (-1 == ret) {
if (errno != EINTR)
perror("select failed");
- return -1;
+ break;
}
CONTINUE_ZERO_RET();
@@ -293,6 +308,8 @@ if (ret < 0) \
#undef MAX
}
+ cleanup_threads(cfg);
+
return status;
}
diff --git a/src/thread.c b/src/thread.c
index bef05ba..69cf768 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -36,7 +36,8 @@ struct lt_thread *lt_thread_add(struct lt_config_app *cfg, int fd, pid_t pid)
memset(t, 0x0, sizeof(*t));
- if (-1 == lt_stats_alloc(cfg, t)) {
+ if (lt_sh(cfg, counts) &&
+ (-1 == lt_stats_alloc(cfg, t))) {
free(t);
return NULL;
}