Hi,
I do not see any benefit in doing linked-list deletions using recursion. It only adds unnecessary stack pressure (think embedded!) for no real advantage:
diff -ur muscleframework-1.1.5-org/libmusclepkcs11/src/p11x_object.c muscleframework-1.1.5/libmusclepkcs11/src/p11x_object.c
--- muscleframework-1.1.5-org/libmusclepkcs11/src/p11x_object.c Fri Nov 28 10:47:13 2003
+++ muscleframework-1.1.5/libmusclepkcs11/src/p11x_object.c Sun Nov 28 10:19:05 2004
@@ -19,22 +19,20 @@
/******************************************************************************
** 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 *n = NULL;
+ for ( ; list ; list = n) {
+ n = list->next;
object_FreeObject(slotID, list);
}
}
@@ -99,25 +97,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 *n;
+ for ( ; list ; list = n)
{
+ n = 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);
}
}
peter
_______________________________________________ Muscle mailing list [EMAIL PROTECTED] http://lists.drizzle.com/mailman/listinfo/muscle
