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
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);
#ifndef PROFILE_SUPPORTS_FOREIGN_NEWLINES
retval = parse_line(bptr, &state);
if (retval) {
+ profile_free_node(state.root_section);
free (bptr);
return retval;
}
newp = p + strlen (p) + 1;
retval = parse_line (p, &state);
if (retval) {
+ profile_free_node(state.root_section);
free (bptr);
return retval;
}
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);
return ENOMEM;
}
}
- new->magic = PROF_MAGIC_NODE;
*ret_node = new;
return 0;