qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Fergeau <cfergeau@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCHv3 4/4] libcacard: don't leak vcard_emul_alloc_arrays mem
Date: Fri, 22 Jul 2011 13:33:30 +0200	[thread overview]
Message-ID: <1311334410-28559-5-git-send-email-cfergeau@redhat.com> (raw)
In-Reply-To: <1311334410-28559-1-git-send-email-cfergeau@redhat.com>

vcard_emul_mirror_card and vcard_emul_init use
vcard_emul_alloc_arrays to allocate memory for temporary arrays
which will contain elements that in the end will be used one by
one in cac_card_init. The arrays themselves are never stored
anywhere, they are only used as temporary containers. Hence
the memory that was allocated for these arrays should be freed
after use or they will be leaked.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
---
 libcacard/vcard_emul_nss.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/libcacard/vcard_emul_nss.c b/libcacard/vcard_emul_nss.c
index de324ba..4fee471 100644
--- a/libcacard/vcard_emul_nss.c
+++ b/libcacard/vcard_emul_nss.c
@@ -476,6 +476,7 @@ vcard_emul_mirror_card(VReader *vreader)
     VCardKey **keys;
     PK11SlotInfo *slot;
     PRBool ret;
+    VCard *card;
 
     slot = vcard_emul_reader_get_slot(vreader);
     if (slot == NULL) {
@@ -535,7 +536,12 @@ vcard_emul_mirror_card(VReader *vreader)
     }
 
     /* now create the card */
-    return vcard_emul_make_card(vreader, certs, cert_len, keys, cert_count);
+    card = vcard_emul_make_card(vreader, certs, cert_len, keys, cert_count);
+    qemu_free(certs);
+    qemu_free(cert_len);
+    qemu_free(keys);
+
+    return card;
 }
 
 static VCardEmulType default_card_type = VCARD_EMUL_NONE;
@@ -820,6 +826,9 @@ vcard_emul_init(const VCardEmulOptions *options)
             vreader_free(vreader);
             has_readers = PR_TRUE;
         }
+        qemu_free(certs);
+        qemu_free(cert_len);
+        qemu_free(keys);
     }
 
     /* if we aren't suppose to use hw, skip looking up hardware tokens */
-- 
1.7.6

  parent reply	other threads:[~2011-07-22 11:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-22 11:33 [Qemu-devel] [PATCHv3 0/4] libcacard fixes Christophe Fergeau
2011-07-22 11:33 ` [Qemu-devel] [PATCHv3 1/4] libcacard: fix soft=... parsing in vcard_emul_options Christophe Fergeau
2011-07-22 11:33 ` [Qemu-devel] [PATCHv3 2/4] libcacard: introduce NEXT_TOKEN macro Christophe Fergeau
2011-07-22 11:33 ` [Qemu-devel] [PATCHv3 3/4] libcacard: replace copy_string with strndup Christophe Fergeau
2011-07-22 11:33 ` Christophe Fergeau [this message]
2011-07-22 11:41 ` [Qemu-devel] [PATCHv3 0/4] libcacard fixes Christophe Fergeau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311334410-28559-5-git-send-email-cfergeau@redhat.com \
    --to=cfergeau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).