[Pcsclite-cvs-commit] CVS PKCS11/src

CVS User rousseau ludovic.rousseau@free.fr
Sun, 28 Nov 2004 08:02:53 -0700


Update of /cvsroot/muscleapps/PKCS11/src
In directory haydn:/tmp/cvs-serv9152

Modified Files:
	p11x_object.c 
Log Message:
object_FreeAllObjects() & object_FreeAllAttributes(): Get rid of useless
recursions
See http://archives.neohapsis.com/archives/dev/muscle/2004-q4/0252.html

Thanks to Peter Stamfest for the patch


--- /cvsroot/muscleapps/PKCS11/src/p11x_object.c	2004/11/28 14:30:31	1.43
+++ /cvsroot/muscleapps/PKCS11/src/p11x_object.c	2004/11/28 15:02:52	1.44
@@ -1,6 +1,6 @@
 /******************************************************************************
 ** 
-**  $Id: p11x_object.c,v 1.43 2004/11/28 14:30:31 rousseau Exp $
+**  $Id: p11x_object.c,v 1.44 2004/11/28 15:02:52 rousseau Exp $
 **
 **  Package: PKCS-11
 **  Author : Chris Osgood <oznet@mac.com>
@@ -19,22 +19,21 @@
 /******************************************************************************
 ** Function: object_FreeAllObjects
 **
-** Recursively releases all objects from the given slot.
+** Releases all objects from the given slot.
 **
 ** Parameters:
 **  slotID - Slot number to release
-**  list   - Object to free (used for recursion)
+**  list   - Object to free
 **
 ** Returns:
 **  none
 *******************************************************************************/
 void object_FreeAllObjects(CK_SLOT_ID slotID, P11_Object *list)
 {
-    if (list)
-    {
-        if (list->next) 
-            object_FreeAllObjects(slotID, list->next);
-        
+	P11_Object *next = NULL;
+	for (; list; list = next)
+	{
+        next = list->next;
         object_FreeObject(slotID, list);
     }
 }
@@ -99,25 +98,25 @@
 ** Deletes/frees all attributes relating to a specific object
 **
 ** Parameters:
-**  list - attribute to free (used for recursion)
+**  list - attribute to free
 **
 ** Returns:
 **  none
 *******************************************************************************/
 void object_FreeAllAttributes(P11_Attrib *list)
 {
-    if (list)
+    P11_Attrib *next;
+    for (; list; list = next)
     {
+	next = list->next;
         log_Log(LOG_LOW, "Removing attribute: %lX", list);
-
-        if (list->next) 
-            object_FreeAllAttributes(list->next);
-
-        if (list->attrib.pValue)
+ 
+        if (list->attrib.pValue) {
+	    memset(list->attrib.pValue, 0x00, list->attrib.ulValueLen);
             free(list->attrib.pValue);
+	}
 
         memset(list, 0x00, sizeof(P11_Attrib));
-
         free(list);
     }
 }