[Pcsclite-git-commit] [PCSC] 01/01: simclist: fix a potential memory leak

Ludovic Rousseau rousseau at moszumanska.debian.org
Thu Jul 13 16:29:34 UTC 2017


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository PCSC.

commit 8946edadaca353d65112664a5fcd7bbe1be54ed5
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Wed Jul 12 17:59:48 2017 +0200

    simclist: fix a potential memory leak
    
    Changes in a801c6e613fde89c09c755a20003ab82fd6a5c47 added tests and
    returns in case of errors.
    
    If something fails in list_insert_at() we must free the memory allocated
    for the new element (that was not inserted).
---
 src/simclist.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/simclist.c b/src/simclist.c
index 27927cd..4f25cdd 100644
--- a/src/simclist.c
+++ b/src/simclist.c
@@ -508,7 +508,10 @@ int list_insert_at(list_t *restrict l, const void *data, unsigned int pos) {
         size_t datalen = l->attrs.meter(data);
         lent->data = (struct list_entry_s *)malloc(datalen);
         if (NULL == lent->data)
+        {
+            free(lent);
             return -1;
+        }
         memcpy(lent->data, data, datalen);
     } else {
         lent->data = (void*)data;
@@ -517,7 +520,11 @@ int list_insert_at(list_t *restrict l, const void *data, unsigned int pos) {
     /* actually append element */
     prec = list_findpos(l, pos-1);
     if (NULL == prec)
+    {
+        free(lent->data);
+        free(lent);
         return -1;
+    }
     succ = prec->next;
 
     prec->next = lent;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git



More information about the Pcsclite-cvs-commit mailing list