Fixed memory leak and added null pointer exceptions when allocating for dlist