From d8de6531f840da742f32e8355ee7af4e6dec0b5a Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Mon, 20 Apr 2015 09:55:57 +0200 Subject: [PATCH] lib: Make iscsi_realloc() update the freed pointer list This patch improves the stability of libiscsi by avoiding that stale pointers are passed to free(). Signed-off-by: Bart Van Assche --- lib/init.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/init.c b/lib/init.c index 1648e59..a9885b1 100644 --- a/lib/init.c +++ b/lib/init.c @@ -49,10 +49,19 @@ void* iscsi_zmalloc(struct iscsi_context *iscsi, size_t size) { } void* iscsi_realloc(struct iscsi_context *iscsi, void* ptr, size_t size) { + int i; void * _ptr = realloc(ptr, size); if (_ptr != NULL) { iscsi->reallocs++; } + if (ptr != NULL) { + for (i = 0; i < iscsi->smalloc_free; i++) { + if (iscsi->smalloc_ptrs[i] == ptr) { + iscsi->smalloc_ptrs[i] = _ptr; + break; + } + } + } return _ptr; }