Bug #81141 Memory leak in NdbDictInterface::parseTableInfo()
Submitted: 19 Apr 2016 12:34 Modified: 10 May 2016 9:40
Reporter: Magnus Blåudd Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Cluster: Cluster (NDB) storage engine Severity:S3 (Non-critical)
Version:7.5.2 OS:Any
Assigned to: CPU Architecture:Any

[19 Apr 2016 12:34] Magnus Blåudd
Description:
Memory leak of tableDesc and other stuff in NdbDictInterface::parseTableInfo() occurs when the function returns without freeing the memory referred by tableDesc.

7.5$> git diff
diff --git a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp
index 5f4b0fc..919f0d5 100644
--- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp
+++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp
@@ -2884,6 +2884,7 @@ NdbDictInterface::parseTableInfo(NdbTableImpl ** ret,
   DBUG_ENTER("NdbDictInterface::parseTableInfo");

   tableDesc = (DictTabInfo::Table*)malloc(sizeof(DictTabInfo::Table));
+                                   ^^^^^^ created
   if (!tableDesc)
   {
     DBUG_RETURN(4000);
@@ -2896,6 +2897,7 @@ NdbDictInterface::parseTableInfo(NdbTableImpl ** ret,

   if(s != SimpleProperties::Break){
     free(tableDesc);
+    ^^^^^ correct
     DBUG_RETURN(703);
   }
   const char * internalName = tableDesc->TableName;
@@ -2912,6 +2914,7 @@ NdbDictInterface::parseTableInfo(NdbTableImpl ** ret,
       impl->m_range.assign((Int32*)tableDesc->RangeListData,
                            /* yuck */tableDesc->RangeListDataLen / 4))
   {
+    ^^^^^^ missing free
     DBUG_RETURN(4000);
   }

@@ -2924,7 +2927,7 @@ NdbDictInterface::parseTableInfo(NdbTableImpl ** ret,
     Uint32 cnt = tableDesc->FragmentDataLen / 2;
     for (Uint32 i = 0; i<cnt; i++)
       if (impl->m_fd.push_back((Uint32)tableDesc->FragmentData[i]))
-        DBUG_RETURN(4000);
+        DBUG_RETURN(4000); <<< missing free
   }

   impl->m_fragmentCount = tableDesc->FragmentCount;
@@ -3007,6 +3010,7 @@ NdbDictInterface::parseTableInfo(NdbTableImpl ** ret,
     if (!impl->m_primaryTable.assign(externalPrimary))
     {
       DBUG_RETURN(4000);
+      ^^^^^^ missing free
     }
     columnsIndexSourced= true;
   }

How to repeat:
MCI

Suggested fix:
Release memory referred by tableDesc before function returns. There might also be some other resource allocated which are not released.

Could probably use some form of auto pointer which would automatically free the memory. The memory used by tableDesc is not returned from the function but only used throughout function.
[10 May 2016 9:40] Jon Stephens
Documented fix in the NDB 7.5.2 changelog, as follows:

    Memory associated with table descriptions was not freed by an
    internal table information method.

Closed.