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 <bart.vanassche@sandisk.com>
This commit is contained in:
committed by
Ronnie Sahlberg
parent
e3e4d8730c
commit
d8de6531f8
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user