server: Avoid invalid memory accesses when create_console_output fails.

Sebastian Lackner sebastian at fds-team.de
Wed Aug 19 05:15:01 CDT 2015


Similar to the previous patches, when the initialization fails in the middle, we have to watch
out that all fields used in the destructor are properly initialized.

In this case the destructor tries to call "list_remove( &screen_buffer->entry )", so we have to
move the call to list_add_head a bit more to the beginning. Also, the destructor tries to free
screen_buffer->data, so initialize with NULL at the beginning.

---
 server/console.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/server/console.c b/server/console.c
index 218831b..0bb1824 100644
--- a/server/console.c
+++ b/server/console.c
@@ -409,6 +409,9 @@ static struct screen_buffer *create_console_output( struct console_input *consol
     screen_buffer->win.right      = screen_buffer->max_width - 1;
     screen_buffer->win.top        = 0;
     screen_buffer->win.bottom     = screen_buffer->max_height - 1;
+    screen_buffer->data           = NULL;
+    list_add_head( &screen_buffer_list, &screen_buffer->entry );
+
     if (fd == -1)
         screen_buffer->fd = NULL;
     else
@@ -422,8 +425,6 @@ static struct screen_buffer *create_console_output( struct console_input *consol
         allow_fd_caching(screen_buffer->fd);
     }
 
-    list_add_head( &screen_buffer_list, &screen_buffer->entry );
-
     if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
                                         sizeof(*screen_buffer->data) )))
     {
-- 
2.5.0



More information about the wine-patches mailing list