[PATCH] wayland-client: Initialize newly created wl_proxys to zero.

Nils Chr. Brause nilschrbrause at gmail.com
Mon Aug 25 02:13:48 PDT 2014


On Tue, Aug 12, 2014 at 09:27:02AM +0200, Marek Chalupa wrote:
> On 11 August 2014 18:02, Nils Chr. Brause <nilschrbrause at gmail.com> wrote:
> 
> > On Mon, Aug 11, 2014 at 08:36:51AM +0200, Marek Chalupa wrote:
> > > >         proxy->flags = 0;
> > > >
> > >
> > > After memset, this line can be removed as well.
> > >
> > >
> > > > @@ -331,10 +331,10 @@ wl_proxy_create_for_id(struct wl_proxy *factory,
> > > >         if (proxy == NULL)
> > > >                 return NULL;
> > > >
> > > > +       memset(proxy, 0, sizeof *proxy);
> > > > +
> > > >         proxy->object.interface = interface;
> > > > -       proxy->object.implementation = NULL;
> > > >         proxy->object.id = id;
> > > > -       proxy->dispatcher = NULL;
> > > >         proxy->display = display;
> > > >         proxy->queue = factory->queue;
> > > >         proxy->flags = 0;
> > > >
> > >
> > > The same.
> > >
> >
> > Yes, of course. I guess we can also remove similar lines from
> > wl_display_connect_to_fd then?
> 
> 
> I think this should be in a separate patch, but let's see what say the
> others.

Comeing back from holidays and seeing that nobody else seems to have
commented on this, I prepared a new patch without the display part:


>From 50cdeaf09a9bd90b1957a831217319e863c4c484 Mon Sep 17 00:00:00 2001
From: "Nils Chr. Brause" <nilschrbrause at googlemail.com>
Date: Mon, 25 Aug 2014 09:46:55 +0200
Subject: [PATCH] wayland-client: Initialize newly created wl_proxys to zero.

Up until now, newly created wl_proxys (with proxy_create or
wl_proxy_create_for_id) are not initialized properly after memory
allocation. The wl_display object in contrast is. To prevent giving
uninitialized data to the user (e.g. user_data) an appropriate memset
has been added. Also, after a memset members don't have to be
explicitly initialized with zero anymore.

Signed-off-by: Nils Chr. Brause <nilschrbrause at googlemail.com>
---
 src/wayland-client.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/wayland-client.c b/src/wayland-client.c
index 9159ee0..88ee2dd 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -270,12 +270,11 @@ proxy_create(struct wl_proxy *factory, const struct wl_interface *interface)
 	if (proxy == NULL)
 		return NULL;
 
+	memset(proxy, 0, sizeof *proxy);
+
 	proxy->object.interface = interface;
-	proxy->object.implementation = NULL;
-	proxy->dispatcher = NULL;
 	proxy->display = display;
 	proxy->queue = factory->queue;
-	proxy->flags = 0;
 	proxy->refcount = 1;
 
 	proxy->object.id = wl_map_insert_new(&display->objects, 0, proxy);
@@ -327,13 +326,12 @@ wl_proxy_create_for_id(struct wl_proxy *factory,
 	if (proxy == NULL)
 		return NULL;
 
+	memset(proxy, 0, sizeof *proxy);
+
 	proxy->object.interface = interface;
-	proxy->object.implementation = NULL;
 	proxy->object.id = id;
-	proxy->dispatcher = NULL;
 	proxy->display = display;
 	proxy->queue = factory->queue;
-	proxy->flags = 0;
 	proxy->refcount = 1;
 
 	wl_map_insert_at(&display->objects, 0, id, proxy);
-- 
2.1.0


More information about the wayland-devel mailing list