@@ -644,13 +644,13 @@ log_server_connect(struct client_closure *closure)
644644}
645645
646646/*
647- * Free client closure and contents, not including log details.
647+ * Free client closure contents, not including log details.
648648 */
649- void
650- client_closure_free (struct client_closure * closure )
649+ static void
650+ client_closure_free_contents (struct client_closure * closure )
651651{
652652 struct connection_buffer * buf ;
653- debug_decl (client_closure_free , SUDOERS_DEBUG_UTIL );
653+ debug_decl (client_closure_free_contents , SUDOERS_DEBUG_UTIL );
654654
655655 if (closure == NULL )
656656 debug_return ;
@@ -661,15 +661,19 @@ client_closure_free(struct client_closure *closure)
661661 if (SSL_shutdown (closure -> ssl ) == 0 )
662662 SSL_shutdown (closure -> ssl );
663663 SSL_free (closure -> ssl );
664+ closure -> ssl = NULL ;
664665 }
665666 SSL_CTX_free (closure -> ssl_ctx );
667+ closure -> ssl_ctx = NULL ;
666668#endif
667669
668670 if (closure -> sock != -1 ) {
669671 shutdown (closure -> sock , SHUT_RDWR );
670672 close (closure -> sock );
673+ closure -> sock = -1 ;
671674 }
672675 free (closure -> server_name );
676+ closure -> server_name = NULL ;
673677 while ((buf = TAILQ_FIRST (& closure -> write_bufs )) != NULL ) {
674678 TAILQ_REMOVE (& closure -> write_bufs , buf , entries );
675679 free (buf -> data );
@@ -680,13 +684,31 @@ client_closure_free(struct client_closure *closure)
680684 free (buf -> data );
681685 free (buf );
682686 }
683- if (closure -> read_ev != NULL )
687+ if (closure -> read_ev != NULL ) {
684688 closure -> read_ev -> free (closure -> read_ev );
685- if (closure -> write_ev != NULL )
689+ closure -> read_ev = NULL ;
690+ }
691+ if (closure -> write_ev != NULL ) {
686692 closure -> write_ev -> free (closure -> write_ev );
693+ closure -> write_ev = NULL ;
694+ }
687695 free (closure -> read_buf .data );
696+ closure -> read_buf .data = NULL ;
688697 free (closure -> iolog_id );
698+ closure -> iolog_id = NULL ;
699+
700+ debug_return ;
701+ }
689702
703+ /*
704+ * Free client closure and contents, not including log details.
705+ */
706+ void
707+ client_closure_free (struct client_closure * closure )
708+ {
709+ debug_decl (client_closure_free , SUDOERS_DEBUG_UTIL );
710+
711+ client_closure_free_contents (closure );
690712 free (closure );
691713
692714 debug_return ;
@@ -1860,13 +1882,13 @@ server_msg_cb(int fd, int what, void *v)
18601882 debug_return ;
18611883bad :
18621884 if (closure -> log_details -> ignore_log_errors ) {
1863- /* Disable plugin , the command continues. */
1885+ /* Disable log server connection , the command continues. */
18641886 closure -> disabled = true;
1865- closure -> read_ev -> del (closure -> read_ev );
18661887 } else {
18671888 /* Break out of sudo event loop and kill the command. */
18681889 closure -> read_ev -> loopbreak (closure -> read_ev );
18691890 }
1891+ client_closure_free_contents (closure );
18701892 debug_return ;
18711893}
18721894
@@ -1981,14 +2003,13 @@ client_msg_cb(int fd, int what, void *v)
19812003
19822004bad :
19832005 if (closure -> log_details -> ignore_log_errors ) {
1984- /* Disable plugin , the command continues. */
2006+ /* Disable log server connection , the command continues. */
19852007 closure -> disabled = true;
1986- closure -> read_ev -> del (closure -> read_ev );
1987- closure -> write_ev -> del (closure -> write_ev );
19882008 } else {
19892009 /* Break out of sudo event loop and kill the command. */
19902010 closure -> write_ev -> loopbreak (closure -> write_ev );
19912011 }
2012+ client_closure_free_contents (closure );
19922013 debug_return ;
19932014}
19942015
0 commit comments