[Spice-devel] [PATCH] Use proper free function for PK11_ReadRawAttribute call

Jakub Jelen jjelen at redhat.com
Tue Aug 14 13:08:22 UTC 2018


On Tue, 2018-08-14 at 10:35 +0100, Frediano Ziglio wrote:
> As documented in PK11_ReadRawAttribute data should be freed with
> PORT_Free, not free or g_free.

Good catch. This might even make the valgrind suppression file slimmer
in the end.

> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  src/cac.c            | 3 ++-
>  src/vcard_emul_nss.c | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/cac.c b/src/cac.c
> index ba63685..6c49d9b 100644
> --- a/src/cac.c
> +++ b/src/cac.c
> @@ -21,6 +21,7 @@
>  
>  #include <string.h>
>  #include <stdbool.h>
> +#include <nss.h>

I don't think we should pull the NSS specific functions in the cac.c.
The vcard_emul_read_object() should probably ensure that it returns
something non-NSS specific that can be freed by standard API (glib?).

>  #include "cac.h"
>  #include "cac-aca.h"
> @@ -728,7 +729,7 @@ cac_passthrough_container_process_apdu(VCard
> *card, VCardAPDU *apdu,
>              data = vcard_emul_read_object(card, pt_applet->label,
> &data_len);
>              if (data) {
>                  tlv = simpletlv_parse(data, data_len, &tlv_len);
> -                g_free(data);
> +                PORT_Free(data);
>  
>                  /* break the data buffer to TL and V buffers */
>                  applet_private->tag_buffer_len =
> cac_create_tl_file(tlv, tlv_len,
> diff --git a/src/vcard_emul_nss.c b/src/vcard_emul_nss.c
> index 9658c5a..b750dce 100644
> --- a/src/vcard_emul_nss.c
> +++ b/src/vcard_emul_nss.c
> @@ -1330,7 +1330,7 @@ vcard_emul_read_object(VCard *card, const char
> *label,
>              && memcmp(label, result.data, result.len) == 0)
>              found = 1;
>  
> -        free(result.data);
> +        PORT_Free(result.data);
>          result.data = NULL;
>  
>          if (found) {

Otherwise, it looks good.

Thanks,
-- 
Jakub Jelen
Software Engineer
Security Technologies
Red Hat, Inc.



More information about the Spice-devel mailing list