[PATCH weston v3 08/36] libweston: strdup head make, model, serial_number

Pekka Paalanen ppaalanen at gmail.com
Tue Oct 31 13:06:23 UTC 2017


On Tue, 31 Oct 2017 13:33:17 +0100
Quentin Glidic <sardemff7+wayland at sardemff7.net> wrote:

> On 10/31/17 12:48 PM, Pekka Paalanen wrote:
> > From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
> > 
> > Duplicate these strings to decouple their lifetime from whatever the
> > backends used. This should prevent hard to catch use after frees and
> > such problems in the future.
> > 
> > Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>  
> 
> Straightforward:
> Reviewed-by: Quentin Glidic <sardemff7+git at sardemff7.net>
> 
> As a nitpick, maybe we could add xstrdup or safe_strdup to handle the 
> NULL case?

You mean strdup() that is safe to call with a NULL argument? I suppose,
yeah. First I was thinking of xstrdup() that would abort() on strdup()
failure. Do both?

I've been thinking that maybe our to_<type>() inline
casting functions should also gracefully deal with NULL.


Thanks,
pq

> > ---
> >   libweston/compositor.c | 14 +++++++++++---
> >   1 file changed, 11 insertions(+), 3 deletions(-)
> > 
> > diff --git a/libweston/compositor.c b/libweston/compositor.c
> > index 1cc5050a..de667cfa 100644
> > --- a/libweston/compositor.c
> > +++ b/libweston/compositor.c
> > @@ -4479,6 +4479,10 @@ static void
> >   weston_head_release(struct weston_head *head)
> >   {
> >   	weston_head_detach(head);
> > +
> > +	free(head->make);
> > +	free(head->model);
> > +	free(head->serial_number);
> >   }
> >   
> >   /** Store monitor make, model and serial number
> > @@ -4500,9 +4504,13 @@ weston_head_set_monitor_strings(struct weston_head *head,
> >   				const char *model,
> >   				const char *serialno)
> >   {
> > -	head->make = (char *)make;
> > -	head->model = (char *)model;
> > -	head->serial_number = (char *)serialno;
> > +	free(head->make);
> > +	free(head->model);
> > +	free(head->serial_number);
> > +
> > +	head->make = make ? strdup(make) : NULL;
> > +	head->model = model ? strdup(model) : NULL;
> > +	head->serial_number = serialno ? strdup(serialno) : NULL;
> >   }
> >   
> >   /** Store physical image size
> >   
> 
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20171031/30a02aa8/attachment.sig>


More information about the wayland-devel mailing list