$OpenBSD: patch-src_simclist_c,v 1.1 2017/08/11 10:06:01 dcoppa Exp $

commit 8946edadaca353d65112664a5fcd7bbe1be54ed5
Author: Ludovic Rousseau <ludovic.rousseau@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).

Index: src/simclist.c
--- src/simclist.c.orig
+++ src/simclist.c
@@ -508,7 +508,10 @@ int list_insert_at(list_t *restrict l, const void *dat
         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 *dat
     /* 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;
