diff --git a/src/vhdldocgen.cpp b/src/vhdldocgen.cpp
index 0617ea6..54e3a97 100644
--- a/src/vhdldocgen.cpp
+++ b/src/vhdldocgen.cpp
@@ -479,8 +479,12 @@ static QList<MemberDef>* getPorts(ClassDef *cd)
   QList<MemberDef> *portList=new QList<MemberDef>;
   MemberList *ml=cd->getMemberList(MemberListType_variableMembers);
 
-  if (ml==0) return NULL;
-
+  if (ml==0)
+  {
+	  delete portlist;
+	  return NULL;
+  }
+  
   MemberListIterator fmni(*ml);
 
   for (fmni.toFirst();(md=fmni.current());++fmni)
