Use safer sizeof variant in malloc
For a local variable:
TYPE *p;
Allocations like this are "risky":
p = OPENSSL_malloc(sizeof(TYPE));
if the type of p changes, and the malloc call isn't updated, you
could get memory corruption. Instead do this:
p = OPENSSL_malloc(sizeof(*p));
Also fixed a few memset() calls that I noticed while doing this.
Reviewed-by: Richard Levitte <levitte@openssl.org>
diff --git a/crypto/pqueue/pqueue.c b/crypto/pqueue/pqueue.c
index 725fe38..d66efe1 100644
--- a/crypto/pqueue/pqueue.c
+++ b/crypto/pqueue/pqueue.c
@@ -68,7 +68,7 @@
pitem *pitem_new(unsigned char *prio64be, void *data)
{
- pitem *item = OPENSSL_malloc(sizeof(pitem));
+ pitem *item = OPENSSL_malloc(sizeof(*item));
if (item == NULL)
return NULL;
@@ -87,7 +87,7 @@
pqueue_s *pqueue_new()
{
- pqueue_s *pq = OPENSSL_malloc(sizeof(pqueue_s));
+ pqueue_s *pq = OPENSSL_malloc(sizeof(*pq));
if (pq == NULL)
return NULL;