[CalendarServer-changes] [4897] PyOpenDirectory/branches/users/gaya/attrmemleaks/src/ CDirectoryService.cpp

source_changes at macosforge.org source_changes at macosforge.org
Tue Jan 5 15:53:03 PST 2010


Revision: 4897
          http://trac.macosforge.org/projects/calendarserver/changeset/4897
Author:   gaya at apple.com
Date:     2010-01-05 15:53:02 -0800 (Tue, 05 Jan 2010)
Log Message:
-----------
fix potential memory leaks from attrValue and attrinfo returned from ::dsGetAttributeEntry()

Modified Paths:
--------------
    PyOpenDirectory/branches/users/gaya/attrmemleaks/src/CDirectoryService.cpp

Modified: PyOpenDirectory/branches/users/gaya/attrmemleaks/src/CDirectoryService.cpp
===================================================================
--- PyOpenDirectory/branches/users/gaya/attrmemleaks/src/CDirectoryService.cpp	2010-01-05 23:33:55 UTC (rev 4896)
+++ PyOpenDirectory/branches/users/gaya/attrmemleaks/src/CDirectoryService.cpp	2010-01-05 23:53:02 UTC (rev 4897)
@@ -345,6 +345,8 @@
     tDataListPtr attrTypes = NULL;
     tContextData context = NULL;
     tAttributeListRef attrListRef = 0L;
+	tAttributeValueListRef attributeValueListRef = 0L;
+	tAttributeEntryPtr attributeInfoPtr = NULL;
 	
     try
     {
@@ -377,8 +379,6 @@
             ThrowIfDSErr(err);
             for(UInt32 i = 1; i <= attrCount; i++)
             {
-				tAttributeValueListRef attributeValueListRef = NULL;
-				tAttributeEntryPtr attributeInfoPtr = NULL;
 				
 				ThrowIfDSErr(::dsGetAttributeEntry(node, mData, attrListRef, i, &attributeValueListRef, &attributeInfoPtr));
 				
@@ -457,6 +457,10 @@
     catch(CDirectoryServiceException& dsStatus)
     {
         // Cleanup
+        if (attributeValueListRef != 0L)
+			::dsCloseAttributeValueList(attributeValueListRef);
+        if (attributeInfoPtr != NULL)
+			::dsDeallocAttributeEntry(mDir, attributeInfoPtr);
         if (context != NULL)
             ::dsReleaseContinueData(mDir, context);
 		
@@ -515,6 +519,8 @@
     tContextData context = NULL;
     tAttributeListRef attrListRef = 0L;
     tRecordEntry* pRecEntry = NULL;
+	tAttributeValueListRef attributeValueListRef = 0L;
+	tAttributeEntryPtr attributeInfoPtr = NULL;
 
     // Must have attributes
     if (::CFDictionaryGetCount(attributes) == 0)
@@ -579,9 +585,6 @@
                 // Look at each requested attribute and get one value
                 for(unsigned long j = 1; j <= pRecEntry->fRecordAttributeCount; j++)
                 {
-                    tAttributeValueListRef attributeValueListRef = NULL;
-                    tAttributeEntryPtr attributeInfoPtr = NULL;
-
                     ThrowIfDSErr(::dsGetAttributeEntry(mNode, mData, attrListRef, j, &attributeValueListRef, &attributeInfoPtr));
 
                     if (attributeInfoPtr->fAttributeValueCount > 0)
@@ -681,6 +684,10 @@
     catch(CDirectoryServiceException& dsStatus)
     {
         // Cleanup
+        if (attributeValueListRef != 0L)
+			::dsCloseAttributeValueList(attributeValueListRef);
+        if (attributeInfoPtr != NULL)
+			::dsDeallocAttributeEntry(mDir, attributeInfoPtr);
         if (context != NULL)
             ::dsReleaseContinueData(mDir, context);
         if (attrListRef != 0L)
@@ -765,7 +772,10 @@
     tContextData context = NULL;
     tAttributeListRef attrListRef = 0L;
     tRecordEntry* pRecEntry = NULL;
+	tAttributeValueListRef attributeValueListRef = 0L;
+	tAttributeEntryPtr attributeInfoPtr = NULL;
 
+
     // Must have attributes
     if (::CFDictionaryGetCount(attributes) == 0)
         return NULL;
@@ -846,9 +856,6 @@
                 // Look at each requested attribute and get one value
                 for(unsigned long j = 1; j <= pRecEntry->fRecordAttributeCount; j++)
                 {
-                    tAttributeValueListRef attributeValueListRef = NULL;
-                    tAttributeEntryPtr attributeInfoPtr = NULL;
-
                     ThrowIfDSErr(::dsGetAttributeEntry(mNode, mData, attrListRef, j, &attributeValueListRef, &attributeInfoPtr));
 
                     if (attributeInfoPtr->fAttributeValueCount > 0)
@@ -947,6 +954,10 @@
     catch(CDirectoryServiceException& dsStatus)
     {
         // Cleanup
+        if (attributeValueListRef != 0L)
+			::dsCloseAttributeValueList(attributeValueListRef);
+        if (attributeInfoPtr != NULL)
+			::dsDeallocAttributeEntry(mDir, attributeInfoPtr);
         if (context != NULL)
             ::dsReleaseContinueData(mDir, context);
         if (attrListRef != 0L)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100105/b174a7ed/attachment.html>


More information about the calendarserver-changes mailing list