diff options
Diffstat (limited to 'security/nss/lib/util')
-rw-r--r-- | security/nss/lib/util/secitem.c | 22 | ||||
-rw-r--r-- | security/nss/lib/util/secitem.h | 7 |
2 files changed, 26 insertions, 3 deletions
diff --git a/security/nss/lib/util/secitem.c b/security/nss/lib/util/secitem.c index eb4683ca4..daf550d62 100644 --- a/security/nss/lib/util/secitem.c +++ b/security/nss/lib/util/secitem.c @@ -180,18 +180,32 @@ SECITEM_ItemsAreEqual(const SECItem *a, const SECItem *b) SECItem * SECITEM_DupItem(const SECItem *from) { + return SECITEM_ArenaDupItem(NULL, from); +} + +SECItem * +SECITEM_ArenaDupItem(PRArenaPool *arena, const SECItem *from) +{ SECItem *to; if ( from == NULL ) { return(NULL); } - to = (SECItem *)PORT_Alloc(sizeof(SECItem)); + if ( arena != NULL ) { + to = (SECItem *)PORT_ArenaAlloc(arena, sizeof(SECItem)); + } else { + to = (SECItem *)PORT_Alloc(sizeof(SECItem)); + } if ( to == NULL ) { return(NULL); } - to->data = (unsigned char *)PORT_Alloc(from->len); + if ( arena != NULL ) { + to->data = (unsigned char *)PORT_ArenaAlloc(arena, from->len); + } else { + to->data = (unsigned char *)PORT_Alloc(from->len); + } if ( to->data == NULL ) { PORT_Free(to); return(NULL); @@ -199,7 +213,9 @@ SECITEM_DupItem(const SECItem *from) to->len = from->len; to->type = from->type; - PORT_Memcpy(to->data, from->data, to->len); + if ( to->len ) { + PORT_Memcpy(to->data, from->data, to->len); + } return(to); } diff --git a/security/nss/lib/util/secitem.h b/security/nss/lib/util/secitem.h index 76a5d16fb..d957ba0eb 100644 --- a/security/nss/lib/util/secitem.h +++ b/security/nss/lib/util/secitem.h @@ -93,6 +93,13 @@ extern SECStatus SECITEM_CopyItem(PRArenaPool *arena, SECItem *to, extern SECItem *SECITEM_DupItem(const SECItem *from); /* +** Allocate an item and copy "from" into it. The item itself and the +** data it points to are both allocated from the arena. If arena is +** NULL, this function is equivalent to SECITEM_DupItem. +*/ +extern SECItem *SECITEM_ArenaDupItem(PRArenaPool *arena, const SECItem *from); + +/* ** Free "zap". If freeit is PR_TRUE then "zap" itself is freed. */ extern void SECITEM_FreeItem(SECItem *zap, PRBool freeit); |