aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2016-06-23 11:12:55 -0400
committerGreg Hudson <ghudson@mit.edu>2016-08-10 17:24:05 -0400
commit4947c270032691d556140b290e1b10846b692968 (patch)
treefd967c980c98b3e8977a81b9c3ce2a6df2441bf8 /src/util
parent73c9944ae86cf3a89e11d3d3f15dd9b8da7b9cd1 (diff)
downloadkrb5-4947c270032691d556140b290e1b10846b692968.zip
krb5-4947c270032691d556140b290e1b10846b692968.tar.gz
krb5-4947c270032691d556140b290e1b10846b692968.tar.bz2
Fix memory leaks in test programs
Eliminate memory leaks detected by asan in test programs, to make it easier to find more serious leaks.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/profile/prof_test110
-rw-r--r--src/util/profile/profile_tcl.c53
2 files changed, 36 insertions, 27 deletions
diff --git a/src/util/profile/prof_test1 b/src/util/profile/prof_test1
index 984eb3b..7e30fc1 100644
--- a/src/util/profile/prof_test1
+++ b/src/util/profile/prof_test1
@@ -21,7 +21,7 @@ proc test1 {} {
}
}
if $verbose { puts "" }
- #profile_iterator_free $iter
+ profile_iterator_free $iter
set iter [profile_iterator_create $p $sect 0]
set done 0
@@ -37,7 +37,7 @@ proc test1 {} {
}
}
if $verbose { puts "" }
- #profile_iterator_free $iter
+ profile_iterator_free $iter
catch {file delete $wd/test3.ini}
profile_flush_to_file $p $wd/test3.ini
profile_abandon $p
@@ -58,7 +58,7 @@ proc test1 {} {
if $verbose { puts -nonewline "\t$val" }
}
}
- #profile_iterator_free $iter
+ profile_iterator_free $iter
profile_abandon $p
if {$found_some} {
@@ -243,6 +243,7 @@ proc test5 {} {
puts stderr, "Error: test5: Wrong results from profile"
exit 1
}
+ profile_release $p
puts "OK: test5: syntax independence of included files"
}
@@ -273,6 +274,7 @@ proc test6 {} {
puts stderr, "Error: test6: Got value from deleted section"
exit 1
}
+ profile_abandon $p
puts "OK: test6: section replacement"
}
@@ -291,6 +293,7 @@ proc test7 {} {
profile_update_relation $p $rel 2
if $verbose { puts "Clearing values at {$rel}" }
profile_clear_relation $p $rel
+ profile_abandon $p
puts "OK: test7: profile_clear_relation with deleted node at end"
}
@@ -314,6 +317,7 @@ proc test8 {} {
puts stderr, "Error: test8: Wrong order of values: $x"
exit 1
}
+ profile_abandon $p
puts "OK: test8: relation order in the presence of deletions"
}
diff --git a/src/util/profile/profile_tcl.c b/src/util/profile/profile_tcl.c
index 505fb80..cac4627 100644
--- a/src/util/profile/profile_tcl.c
+++ b/src/util/profile/profile_tcl.c
@@ -1712,7 +1712,10 @@ static void my_tcl_setresult(Tcl_Interp *i, const char *str, Tcl_FreeProc *f)
#endif
-typedef void **iter_t; /* ick */
+typedef struct {
+ void *handle;
+ char **args;
+} *iter_t;
SWIGINTERN int
@@ -1789,50 +1792,49 @@ SWIG_From_int (int value)
}
+static void iter_free(iter_t it)
+{
+ int i;
+
+ for (i = 0; it->args != NULL && it->args[i] != NULL; i++)
+ free(it->args[i]);
+ free(it->args);
+ profile_iterator_free(&it->handle);
+ free(it);
+}
+
static errcode_t iter_create(profile_t p, const char **nullterm,
int flags, iter_t *OUTPUT)
{
iter_t it;
errcode_t err;
- const char **args;
it = malloc(sizeof(*it));
if (it == NULL)
return ENOMEM;
{
- /* Memory leak!
-
- The profile code seems to assume that I'll keep the string
- array around for as long as the iterator is valid; I can't
- create the iterator and then throw them away.
-
- But right now, I can't be bothered to track the necessary
- information to do the cleanup later. */
+ /* The current implementation requires that the names be kept around
+ * for the lifetime of the iterator. */
int count, j;
for (count = 0; nullterm[count]; count++) ;
- args = calloc(count+1, sizeof(char *));
- if (args == NULL)
+ it->args = calloc(count + 1, sizeof(*it->args));
+ if (it->args == NULL)
return ENOMEM;
for (j = 0; j < count; j++) {
- args[j] = strdup(nullterm[j]);
- if (args[j] == NULL)
+ it->args[j] = strdup(nullterm[j]);
+ if (it->args[j] == NULL)
return ENOMEM;
}
- args[j] = NULL;
+ it->args[j] = NULL;
}
- err = profile_iterator_create(p, args, flags, it);
+ err = profile_iterator_create(p, (const char **)it->args, flags,
+ &it->handle);
if (err)
- free(it);
+ iter_free(it);
else
*OUTPUT = it;
return err;
}
-static void iter_free(iter_t i)
-{
- profile_iterator_free(i);
- free(i);
-}
-
/* A TCL_AppInit() function that lets you build a new copy
@@ -2137,6 +2139,7 @@ _wrap_profile_get_values(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, i
for (i = 0; (*arg3)[i]; i++)
Tcl_AppendElement(interp, (*arg3)[i]);
}
+ profile_free_list(*arg3);
{
/* freearg char **nullterm */
if (arg2) {
@@ -2642,7 +2645,7 @@ _wrap_profile_iterator(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "profile_iterator" "', argument " "1"" of type '" "iter_t""'");
}
arg1 = (iter_t)(argp1);
- result = (errcode_t)profile_iterator(arg1,arg2,arg3);
+ result = (errcode_t)profile_iterator(&arg1->handle,arg2,arg3);
{
/* out errcode_t result */
if (result) {
@@ -2659,6 +2662,7 @@ _wrap_profile_iterator(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int
Tcl_ListObjAppendElement(interp, Tcl_GetObjResult(interp),
Tcl_NewStringObj(s, strlen(s)));
}
+ profile_release_string(*arg2);
{
/* argout char **OUTPUT */
/* Tcl_SetResult(interp, *arg3, TCL_DYNAMIC); */
@@ -2666,6 +2670,7 @@ _wrap_profile_iterator(ClientData clientData SWIGUNUSED, Tcl_Interp *interp, int
Tcl_ListObjAppendElement(interp, Tcl_GetObjResult(interp),
Tcl_NewStringObj(s, strlen(s)));
}
+ profile_release_string(*arg3);
return TCL_OK;
fail:
return TCL_ERROR;