[Spice-devel] [PATCH spice-server 1/6] spicevmc: Use spice_new instead of spice_malloc
Frediano Ziglio
fziglio at redhat.com
Tue Feb 28 10:22:26 UTC 2017
Ping
----- Original Message -----
> From: "Frediano Ziglio" <fziglio at redhat.com>
> To: uril at redhat.com
> Cc: spice-devel at lists.freedesktop.org
> Sent: Thursday, January 26, 2017 2:43:37 PM
> Subject: Re: [Spice-devel] [PATCH spice-server 1/6] spicevmc: Use spice_new instead of spice_malloc
>
> >
> > On 01/26/2017 12:56 PM, Frediano Ziglio wrote:
> > > spice_new is a bit more safe as return a properly typed pointer.
> >
> > Hi Frediano,
> >
> > I do not think it's much safer, as spice_new is just
>
> As I said it's a bit safer, not much :-)
>
> > a #define macro that (with second param 1)
> > calls spice_malloc and casts from void* ; but
>
> Yes, this is why is safer, returning a typeX * make sure
> you can't do something like
>
> typeY *p = spice_new0(typeX, 1);
>
> which give conversion error.
>
> > it does not hurt either, so fine by me.
> >
> > Uri.
> >
> > >
> > > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > > ---
> > > server/spicevmc.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/server/spicevmc.c b/server/spicevmc.c
> > > index bbe72b5..0dc2b19 100644
> > > --- a/server/spicevmc.c
> > > +++ b/server/spicevmc.c
> > > @@ -380,7 +380,7 @@ static void spicevmc_port_send_init(RedChannelClient
> > > *rcc)
> > > {
> > > RedVmcChannel *channel =
> > > RED_VMC_CHANNEL(red_channel_client_get_channel(rcc));
> > > SpiceCharDeviceInstance *sin = channel->chardev_sin;
> > > - RedPortInitPipeItem *item =
> > > spice_malloc(sizeof(RedPortInitPipeItem));
> > > + RedPortInitPipeItem *item = spice_new(RedPortInitPipeItem, 1);
> > >
> > > red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_PORT_INIT);
> > > item->name = strdup(sin->portname);
> > > @@ -390,7 +390,7 @@ static void spicevmc_port_send_init(RedChannelClient
> > > *rcc)
> > >
> > > static void spicevmc_port_send_event(RedChannelClient *rcc, uint8_t
> > > event)
> > > {
> > > - RedPortEventPipeItem *item =
> > > spice_malloc(sizeof(RedPortEventPipeItem));
> > > + RedPortEventPipeItem *item = spice_new(RedPortEventPipeItem, 1);
> > >
> > > red_pipe_item_init(&item->base, RED_PIPE_ITEM_TYPE_PORT_EVENT);
> > > item->event = event;
> > >
> >
More information about the Spice-devel
mailing list