Eric Blake <e...@byu.net> writes: > According to Simon Josefsson on 11/13/2009 2:53 AM: >> + >> + result = my_xasprintf (""); >> + ASSERT (result != NULL); >> + ASSERT (strcmp (result, "") == 0); >> + > > Don't forget to free() result between each test, so that we don't keep > leaking memory.
Thanks, fixed as per below. Also ran under valgrind and there were no memory leaks. /Simon >From eeb7039f209f06a460dc50b41956d7a07e2d2a32 Mon Sep 17 00:00:00 2001 From: Simon Josefsson <si...@josefsson.org> Date: Fri, 13 Nov 2009 13:53:01 +0100 Subject: [PATCH] tests/test-xvasprintf.c: Fix memory leak. --- ChangeLog | 5 +++++ tests/test-xvasprintf.c | 8 ++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) diff --git a/ChangeLog b/ChangeLog index 34915a0..b6a1a29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-11-13 Simon Josefsson <si...@josefsson.org> + * tests/test-xvasprintf.c: Fix memory leak, suggested by Eric + Blake <e...@byu.net>. + +2009-11-13 Simon Josefsson <si...@josefsson.org> + * tests/test-xvasprintf.c: Add %s%s related checks. 2009-11-12 Eric Blake <e...@byu.net> diff --git a/tests/test-xvasprintf.c b/tests/test-xvasprintf.c index 5296b67..229e3fd 100644 --- a/tests/test-xvasprintf.c +++ b/tests/test-xvasprintf.c @@ -68,18 +68,22 @@ test_xvasprintf (void) result = my_xasprintf (""); ASSERT (result != NULL); ASSERT (strcmp (result, "") == 0); + free (result); result = my_xasprintf ("%s", "foo"); ASSERT (result != NULL); ASSERT (strcmp (result, "foo") == 0); + free (result); result = my_xasprintf ("%s%s", "foo", "bar"); ASSERT (result != NULL); ASSERT (strcmp (result, "foobar") == 0); + free (result); result = my_xasprintf ("%s%sbaz", "foo", "bar"); ASSERT (result != NULL); ASSERT (strcmp (result, "foobarbaz") == 0); + free (result); } static void @@ -99,18 +103,22 @@ test_xasprintf () result = xasprintf (""); ASSERT (result != NULL); ASSERT (strcmp (result, "") == 0); + free (result); result = xasprintf ("%s", "foo"); ASSERT (result != NULL); ASSERT (strcmp (result, "foo") == 0); + free (result); result = xasprintf ("%s%s", "foo", "bar"); ASSERT (result != NULL); ASSERT (strcmp (result, "foobar") == 0); + free (result); result = my_xasprintf ("%s%sbaz", "foo", "bar"); ASSERT (result != NULL); ASSERT (strcmp (result, "foobarbaz") == 0); + free (result); } int -- 1.6.5.2