[notmuch] [PATCH 2/2] * free the response data from 'prompt'

2009-12-04 Thread Carl Worth
On Wed,  2 Dec 2009 09:11:25 +0200, "Dirk-Jan C. Binnema"  wrote:
> Free the results of the prompt; this patch does the minimal job for that.
> It may be nice to refactor the function a bit. 
> 
> Signed-off-by: Dirk-Jan C. Binnema 

Hi there,

I pushed the first leak fix from this series, but the below is doing a
little more work than necessary.

The getline function is happy to accept a malloc'ed pointer and return
it again if it's large enough, (or otherwise realloc it and return the
result).

So we don't need to free response between each call to prompt, but just
after the last one.

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[notmuch] [PATCH 2/2] * free the response data from 'prompt'

2009-12-02 Thread Dirk-Jan C. Binnema
Free the results of the prompt; this patch does the minimal job for that.
It may be nice to refactor the function a bit. 

Signed-off-by: Dirk-Jan C. Binnema 
---
 notmuch-setup.c |   15 +--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/notmuch-setup.c b/notmuch-setup.c
index 622bbaa..293c852 100644
--- a/notmuch-setup.c
+++ b/notmuch-setup.c
@@ -119,12 +119,16 @@ notmuch_setup_command (unused (void *ctx),
 prompt ("Your full name [%s]: ", notmuch_config_get_user_name (config));
 if (strlen (response))
notmuch_config_set_user_name (config, response);
-
+free (response);
+response = NULL;
+
 prompt ("Your primary email address [%s]: ",
notmuch_config_get_user_primary_email (config));
 if (strlen (response))
notmuch_config_set_user_primary_email (config, response);
-
+free (response);
+response = NULL;
+
 other_emails = g_ptr_array_new ();

 old_other_emails = notmuch_config_get_user_other_email (config,
@@ -136,12 +140,17 @@ notmuch_setup_command (unused (void *ctx),
else
g_ptr_array_add (other_emails, talloc_strdup (ctx,
 old_other_emails[i]));
+   free (response);
+   response = NULL;
 }

 do {
prompt ("Additional email address [Press 'Enter' if none]: ");
if (strlen (response))
g_ptr_array_add (other_emails, talloc_strdup (ctx, response));
+   free (response);
+   response = NULL;
+   
 } while (strlen (response));
 if (other_emails->len)
notmuch_config_set_user_other_email (config,
@@ -158,6 +167,8 @@ notmuch_setup_command (unused (void *ctx),
absolute_path = make_path_absolute (ctx, response);
notmuch_config_set_database_path (config, absolute_path);
 }
+free (response);
+response = NULL;

 if (! notmuch_config_save (config)) {
if (is_new)
-- 
1.6.3.3