[PATCH 1/8] server: Allocate extra_bytes separatelly from window struct.
Signed-off-by: Jacek Caban <jacek(a)codeweavers.com> --- We will eventually use window_shared for that when it's ready. server/window.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
On Tue, Feb 08, 2022 at 12:26:46PM +0100, Jacek Caban wrote:
Signed-off-by: Jacek Caban <jacek(a)codeweavers.com> --- We will eventually use window_shared for that when it's ready.
server/window.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/server/window.c b/server/window.c index 7ea91d2a7dc..366f1fd9c44 100644 --- a/server/window.c +++ b/server/window.c @@ -93,7 +93,7 @@ struct window int prop_alloc; /* number of allocated window properties */ struct property *properties; /* window properties array */ int nb_extra_bytes; /* number of extra bytes */ - char extra_bytes[1]; /* extra bytes storage */ + char *extra_bytes; /* extra bytes storage */ };
/* flags that can be set by the client */ @@ -483,7 +483,8 @@ static struct window *create_window( struct window *parent, struct window *owner goto failed; }
- if (!(win = mem_alloc( sizeof(*win) + extra_bytes - 1 ))) goto failed; + if (!(win = mem_alloc( sizeof(*win) ))) goto failed; + if (extra_bytes && !(win->extra_bytes = mem_alloc( extra_bytes ))) goto failed; if (!(win->handle = alloc_user_handle( win, USER_WINDOW ))) goto failed;
Don't you need to NULL-init win->extra_bytes in the !extra_bytes case (at the very least for the failed: block below).
win->parent = parent; @@ -553,6 +554,7 @@ failed: if (win) { if (win->handle) free_user_handle( win->handle ); + free( win->extra_bytes ); free( win ); } release_object( desktop ); @@ -1920,6 +1922,11 @@ void destroy_window( struct window *win ) if (win->update_region) free_region( win->update_region ); if (win->class) release_class( win->class ); free( win->text ); + if (win->nb_extra_bytes) + { + memset( win->extra_bytes, 0x55, win->nb_extra_bytes ); + free( win->extra_bytes ); + } memset( win, 0x55, sizeof(*win) + win->nb_extra_bytes - 1 );
This should now just be sizeof(*win)
free( win ); }
Huw.
On 2/8/22 12:45, Huw Davies wrote:
On Tue, Feb 08, 2022 at 12:26:46PM +0100, Jacek Caban wrote:
Signed-off-by: Jacek Caban <jacek(a)codeweavers.com> --- We will eventually use window_shared for that when it's ready.
server/window.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/server/window.c b/server/window.c index 7ea91d2a7dc..366f1fd9c44 100644 --- a/server/window.c +++ b/server/window.c @@ -93,7 +93,7 @@ struct window int prop_alloc; /* number of allocated window properties */ struct property *properties; /* window properties array */ int nb_extra_bytes; /* number of extra bytes */ - char extra_bytes[1]; /* extra bytes storage */ + char *extra_bytes; /* extra bytes storage */ };
/* flags that can be set by the client */ @@ -483,7 +483,8 @@ static struct window *create_window( struct window *parent, struct window *owner goto failed; }
- if (!(win = mem_alloc( sizeof(*win) + extra_bytes - 1 ))) goto failed; + if (!(win = mem_alloc( sizeof(*win) ))) goto failed; + if (extra_bytes && !(win->extra_bytes = mem_alloc( extra_bytes ))) goto failed; if (!(win->handle = alloc_user_handle( win, USER_WINDOW ))) goto failed; Don't you need to NULL-init win->extra_bytes in the !extra_bytes case (at the very least for the failed: block below).
Yes, I messed it up. It would be probably cleaner to move part of patch 2 here anyway, I will send a fixed version. Thanks, Jacek
participants (2)
-
Huw Davies -
Jacek Caban