Commit f84bcd99 f84bcd99f10ab957af4c84601f9aaaeb43de98b7 by Sergey Poznyakoff

Improve memory allocation in pop3d.

* pop3d/pop3d.c (pop3d_alloc_die): New function.
(main): Set mu_alloc_die_hook.
(pop3d_mainloop): Use mu_alloc.
* pop3d/pop3d.h: Include mailutils/alloc.h
1 parent 6ffef584
...@@ -301,9 +301,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) ...@@ -301,9 +301,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
301 /* Prepare the shared secret for APOP. */ 301 /* Prepare the shared secret for APOP. */
302 { 302 {
303 char *local_hostname; 303 char *local_hostname;
304 local_hostname = malloc (MAXHOSTNAMELEN + 1); 304 local_hostname = mu_alloc (MAXHOSTNAMELEN + 1);
305 if (local_hostname == NULL)
306 pop3d_abquit (ERR_NO_MEM);
307 305
308 /* Get our canonical hostname. */ 306 /* Get our canonical hostname. */
309 { 307 {
...@@ -317,9 +315,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile) ...@@ -317,9 +315,7 @@ pop3d_mainloop (int fd, FILE *infile, FILE *outfile)
317 } 315 }
318 } 316 }
319 317
320 md5shared = malloc (strlen (local_hostname) + 51); 318 md5shared = mu_alloc (strlen (local_hostname) + 51);
321 if (md5shared == NULL)
322 pop3d_abquit (ERR_NO_MEM);
323 319
324 snprintf (md5shared, strlen (local_hostname) + 50, "<%u.%u@%s>", getpid (), 320 snprintf (md5shared, strlen (local_hostname) + 50, "<%u.%u@%s>", getpid (),
325 (unsigned)time (NULL), local_hostname); 321 (unsigned)time (NULL), local_hostname);
...@@ -388,6 +384,12 @@ pop3d_connection (int fd, struct sockaddr *sa, int salen, void *data, ...@@ -388,6 +384,12 @@ pop3d_connection (int fd, struct sockaddr *sa, int salen, void *data,
388 return 0; 384 return 0;
389 } 385 }
390 386
387 static void
388 pop3d_alloc_die ()
389 {
390 pop3d_abquit (ERR_NO_MEM);
391 }
392
391 int 393 int
392 main (int argc, char **argv) 394 main (int argc, char **argv)
393 { 395 {
...@@ -422,6 +424,8 @@ main (int argc, char **argv) ...@@ -422,6 +424,8 @@ main (int argc, char **argv)
422 mu_m_server_set_timeout (server, 600); 424 mu_m_server_set_timeout (server, 600);
423 mu_m_server_set_strexit (server, mu_strexit); 425 mu_m_server_set_strexit (server, mu_strexit);
424 426
427 mu_alloc_die_hook = pop3d_alloc_die;
428
425 if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param, 429 if (mu_app_init (&argp, pop3d_argp_capa, pop3d_cfg_param,
426 argc, argv, 0, NULL, server)) 430 argc, argv, 0, NULL, server))
427 exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */ 431 exit (EX_CONFIG); /* FIXME: No way to discern from EX_USAGE? */
......
...@@ -101,6 +101,7 @@ extern int expire_on_exit; ...@@ -101,6 +101,7 @@ extern int expire_on_exit;
101 #endif 101 #endif
102 #include <sysexits.h> 102 #include <sysexits.h>
103 103
104 #include <mailutils/alloc.h>
104 #include <mailutils/cctype.h> 105 #include <mailutils/cctype.h>
105 #include <mailutils/cstr.h> 106 #include <mailutils/cstr.h>
106 #include <mailutils/attribute.h> 107 #include <mailutils/attribute.h>
......