Hi all,

* No need to check for NULL before free.
* No need to cast the return value of the allocation functions.
* Do not use malloc() + memset(), simply use calloc()

Tested against the regression tests for pqueue.

ok?

===================================================================
--- pqueue.orig/pqueue.c
+++ pqueue/pqueue.c
@@ -69,8 +69,9 @@ typedef struct _pqueue {
 pitem *
 pitem_new(unsigned char *prio64be, void *data)
 {
-       pitem *item = (pitem *)malloc(sizeof(pitem));
+       pitem *item;
 
+       item = malloc(sizeof(pitem));
        if (item == NULL)
                return NULL;
 
@@ -85,30 +86,18 @@ pitem_new(unsigned char *prio64be, void
 void
 pitem_free(pitem *item)
 {
-       if (item == NULL)
-               return;
-
        free(item);
 }
 
 pqueue_s *
 pqueue_new(void)
 {
-       pqueue_s *pq = (pqueue_s *)malloc(sizeof(pqueue_s));
-
-       if (pq == NULL)
-               return NULL;
-
-       memset(pq, 0x00, sizeof(pqueue_s));
-       return pq;
+       return calloc(1, sizeof(pqueue_s));
 }
 
 void
 pqueue_free(pqueue_s *pq)
 {
-       if (pq == NULL)
-               return;
-
        free(pq);
 }
 

Reply via email to