diff options
-rw-r--r-- | lib/util/secitem.c | 13 | ||||
-rw-r--r-- | lib/util/secitem.h | 3 |
2 files changed, 9 insertions, 7 deletions
diff --git a/lib/util/secitem.c b/lib/util/secitem.c index 40c7f2fa2..49364c72e 100644 --- a/lib/util/secitem.c +++ b/lib/util/secitem.c @@ -131,13 +131,17 @@ SECITEM_ReallocItemV2(PLArenaPool *arena, SECItem *item, unsigned int newlen) } if (!newlen) { - SECITEM_FreeItem(item, PR_FALSE); + if (!arena) { + PORT_Free(item->data); + } + item->data = NULL; + item->len = 0; return SECSuccess; } - if (!item->len) { + if (!item->data) { /* allocate fresh block of memory */ - PORT_Assert(!item->data); + PORT_Assert(!item->len); if (arena) { newdata = PORT_ArenaAlloc(arena, newlen); } else { @@ -154,9 +158,8 @@ SECITEM_ReallocItemV2(PLArenaPool *arena, SECItem *item, unsigned int newlen) */ item->len = newlen; return SECSuccess; - } else { - newdata = PORT_ArenaGrow(arena, item->data, item->len, newlen); } + newdata = PORT_ArenaGrow(arena, item->data, item->len, newlen); } else { newdata = PORT_Realloc(item->data, newlen); } diff --git a/lib/util/secitem.h b/lib/util/secitem.h index 5d2d107fa..290f2e596 100644 --- a/lib/util/secitem.h +++ b/lib/util/secitem.h @@ -55,8 +55,7 @@ extern SECStatus SECITEM_ReallocItem( /* deprecated function */ /* ** Reallocate the data for the specified "item". If "arena" is not NULL, ** then reallocate from there, otherwise reallocate from the heap. -** If the item already has at least the request new size, -** then the item is kept unchanged and SECSuccess is returned. +** If item->data is NULL, the data is allocated (not reallocated). ** In any case, "item" is expected to be a valid SECItem pointer; ** SECFailure is returned if it is not, and the item will remain unchanged. ** If the allocation succeeds, the item is updated and SECSuccess is returned. |