[Spice-devel] [cacard 4/7] simpletlv: Use g_malloc instead of malloc

Christophe Fergeau cfergeau at redhat.com
Fri Aug 10 10:58:30 UTC 2018


On Fri, Aug 10, 2018 at 11:54:47AM +0200, Marc-André Lureau wrote:
> On Fri, Aug 10, 2018 at 10:04 AM, Christophe Fergeau
> <cfergeau at redhat.com> wrote:
> > This is more consistent with the rest of the codebase.
> >
> > Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
> > ---
> >  src/simpletlv.c | 25 +++++++------------------
> >  1 file changed, 7 insertions(+), 18 deletions(-)
> >
> > diff --git a/src/simpletlv.c b/src/simpletlv.c
> > index 42ff572..17ab90e 100644
> > --- a/src/simpletlv.c
> > +++ b/src/simpletlv.c
> > @@ -25,6 +25,7 @@
> >  #include "config.h"
> >  #endif
> >
> > +#include <glib.h>
> >  #include <stdio.h>
> >  #include <string.h>
> >  #include <ctype.h>
> > @@ -86,10 +87,7 @@ simpletlv_encode_internal(struct simpletlv_member *tlv, size_t tlv_len,
> >
> >      if (outlen == 0) {
> >          /* allocate a new buffer */
> > -        a = malloc(expect_len);
> > -        if (a == NULL) {
> > -            return -1;
> > -        }
> > +        a = g_malloc(expect_len);
> >          tmp = a;
> >          tmp_len = expect_len;
> >      } else if ((int)outlen >= expect_len) {
> > @@ -250,11 +248,9 @@ simpletlv_merge(const struct simpletlv_member *a, size_t a_len,
> >      struct simpletlv_member *r;
> >      size_t r_len = a_len + b_len;
> >
> > -    r = malloc(r_len * sizeof(struct simpletlv_member));
> > -    if (r == NULL)
> > -        return NULL;
> > +    r = g_malloc_n(r_len, sizeof(struct simpletlv_member));
> 
> Why not g_new?

libcacard makes mixed use of g_malloc_n and g_new, I thought only
g_malloc_n was used, and wanted to stay consistent. I'll change it and
do the s/free/g_free at the same time.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180810/e7d4d23a/attachment.sig>


More information about the Spice-devel mailing list