Ticket #30176: 0002-Clear-memory-in-smartlist_remove_keeporder.patch

File 0002-Clear-memory-in-smartlist_remove_keeporder.patch, 1.2 KB (added by paldium, 2 months ago)
  • src/lib/smartlist_core/smartlist_core.c

    From eccf7907b45cf7141c2e85ec97cd06c4fd71086c Mon Sep 17 00:00:00 2001
    From: Tobias Stoeckmann <tobias@stoeckmann.org>
    Date: Sat, 13 Apr 2019 16:55:36 +0200
    Subject: [PATCH 2/2] Clear memory in smartlist_remove_keeporder.
    
    The smartlist functions take great care to reset unused pointers inside
    the smartlist memory to NULL.
    
    The function smartlist_remove_keeporder does not clear memory in such
    way when elements have been removed. Therefore call memset after the
    for-loop that removes elements. If no element is removed, it is
    effectively a no-op.
    
    Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
    ---
     src/lib/smartlist_core/smartlist_core.c | 2 ++
     1 file changed, 2 insertions(+)
    
    diff --git a/src/lib/smartlist_core/smartlist_core.c b/src/lib/smartlist_core/smartlist_core.c
    index 5947e7627..6b0a305a9 100644
    a b smartlist_remove_keeporder(smartlist_t *sl, const void *element) 
    177177      sl->list[i++] = sl->list[j];
    178178    }
    179179  }
     180  memset(sl->list + sl->num_used, 0,
     181         sizeof(void *) * (num_used_orig - sl->num_used));
    180182}
    181183
    182184/** If <b>sl</b> is nonempty, remove and return the final element.  Otherwise,