summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEzra Peisach <epeisach@mit.edu>2007-09-26 15:15:33 +0000
committerEzra Peisach <epeisach@mit.edu>2007-09-26 15:15:33 +0000
commitcf3a311a561ade506913c4ba0e38b6e5adf9f9b4 (patch)
tree6e6f9c9674dda75178f76baf3bfb8b2ae6ae8950 /src
parent15b107eb626219ec807730f36c73a1e3fb4b35a4 (diff)
profile library memory leaks introduced when malloc returns 0
I have a modified version of valgrind that will allow me to have malloc fail in a controlled way. A number of memory leaks in error return passes exist in the profile library. They are essentially inconsequental - but my goal is to eventually create a test harness that tries to cover all code - including error returns... prof_parse.c: (profile_parse_file): Free node being created if parse_line() fails. prof_file.c (profile_open_file): free prf_data_t on malloc failure prof_tree.c (profile_create_node): The magic element must be set before calling profile_free_node for it to release memory. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19981 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src')
-rw-r--r--src/util/profile/prof_file.c4
-rw-r--r--src/util/profile/prof_parse.c2
-rw-r--r--src/util/profile/prof_tree.c3
3 files changed, 7 insertions, 2 deletions
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c
index 74d553ee6..cb9bfbc5a 100644
--- a/src/util/profile/prof_file.c
+++ b/src/util/profile/prof_file.c
@@ -226,8 +226,10 @@ errcode_t profile_open_file(const_profile_filespec_t filespec,
len += strlen(home_env);
}
expanded_filename = malloc(len);
- if (expanded_filename == 0)
+ if (expanded_filename == 0) {
+ free(prf);
return errno;
+ }
if (home_env) {
strcpy(expanded_filename, home_env);
strcat(expanded_filename, filespec+1);
diff --git a/src/util/profile/prof_parse.c b/src/util/profile/prof_parse.c
index db491591d..665b9d90c 100644
--- a/src/util/profile/prof_parse.c
+++ b/src/util/profile/prof_parse.c
@@ -242,6 +242,7 @@ errcode_t profile_parse_file(FILE *f, struct profile_node **root)
#ifndef PROFILE_SUPPORTS_FOREIGN_NEWLINES
retval = parse_line(bptr, &state);
if (retval) {
+ profile_free_node(state.root_section);
free (bptr);
return retval;
}
@@ -286,6 +287,7 @@ errcode_t profile_parse_file(FILE *f, struct profile_node **root)
newp = p + strlen (p) + 1;
retval = parse_line (p, &state);
if (retval) {
+ profile_free_node(state.root_section);
free (bptr);
return retval;
}
diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c
index b014e245d..2ea02a547 100644
--- a/src/util/profile/prof_tree.c
+++ b/src/util/profile/prof_tree.c
@@ -92,6 +92,8 @@ errcode_t profile_create_node(const char *name, const char *value,
if (!new)
return ENOMEM;
memset(new, 0, sizeof(struct profile_node));
+ /* Set magic here so profile_free_node will free memory */
+ new->magic = PROF_MAGIC_NODE;
new->name = strdup(name);
if (new->name == 0) {
profile_free_node(new);
@@ -104,7 +106,6 @@ errcode_t profile_create_node(const char *name, const char *value,
return ENOMEM;
}
}
- new->magic = PROF_MAGIC_NODE;
*ret_node = new;
return 0;