fix segfault
[apps/madmutt.git] / mutt_ssl.c
index f73cca7..6a83032 100644 (file)
@@ -22,6 +22,8 @@
 
 #include <string.h>
 
+#include <lib-lib/mem.h>
+
 #include "mutt.h"
 #include "mutt_socket.h"
 #include "mutt_menu.h"
@@ -64,7 +66,7 @@ typedef struct _sslsockdata {
 } sslsockdata;
 
 /* local prototypes */
-int ssl_init (void);
+static int ssl_init (void);
 static int add_entropy (const char *file);
 static int ssl_socket_read (CONNECTION * conn, char *buf, size_t len);
 static int ssl_socket_write (CONNECTION * conn, const char *buf, size_t len);
@@ -86,7 +88,7 @@ int mutt_ssl_starttls (CONNECTION * conn)
   if (ssl_init ())
     goto bail;
 
-  ssldata = (sslsockdata *) mem_calloc (1, sizeof (sslsockdata));
+  ssldata = p_new(sslsockdata, 1);
   /* the ssl_use_xxx protocol options don't apply. We must use TLS in TLS. */
   if (!(ssldata->ctx = SSL_CTX_new (TLSv1_client_method ()))) {
     debug_print (1, ("Error allocating SSL_CTX\n"));
@@ -120,11 +122,11 @@ int mutt_ssl_starttls (CONNECTION * conn)
   return 0;
 
 bail_ssl:
-  mem_free (&ssldata->ssl);
+  p_delete(&ssldata->ssl);
 bail_ctx:
-  mem_free (&ssldata->ctx);
+  p_delete(&ssldata->ctx);
 bail_ssldata:
-  mem_free (&ssldata);
+  p_delete(&ssldata);
 bail:
   return -1;
 }
@@ -258,7 +260,7 @@ static int ssl_socket_open (CONNECTION * conn)
   if (raw_socket_open (conn) < 0)
     return -1;
 
-  data = (sslsockdata *) mem_calloc (1, sizeof (sslsockdata));
+  data = p_new(sslsockdata, 1);
   conn->sockdata = data;
 
   data->ctx = SSL_CTX_new (SSLv23_client_method ());
@@ -350,7 +352,7 @@ static int ssl_socket_close (CONNECTION * conn)
 #endif
     SSL_free (data->ssl);
     SSL_CTX_free (data->ctx);
-    mem_free (&conn->sockdata);
+    p_delete(&conn->sockdata);
   }
 
   return raw_socket_close (conn);
@@ -584,9 +586,9 @@ static int ssl_check_certificate (sslsockdata * data)
   /* interactive check from user */
   menu = mutt_new_menu ();
   menu->max = 19;
-  menu->dialog = (char **) mem_calloc (1, menu->max * sizeof (char *));
+  menu->dialog = p_new(char *, menu->max);
   for (i = 0; i < menu->max; i++)
-    menu->dialog[i] = (char *) mem_calloc (1, SHORT_STRING * sizeof (char));
+    menu->dialog[i] = p_new(char, SHORT_STRING);
 
   row = 0;
   strfcpy (menu->dialog[row], _("This certificate belongs to:"),