Explorar el Código

Revert "Issue#185: Memory double-free in multi-instance classes"

This reverts commit 88038c4739ea69ecde655973b9f0fb036a0d9448.

This fixed the memory double-free for multi-instance classes but only for
the case if the multiple instances were allocated at once when
CreateCipClass() is called with "number_of_instances" > 0 and no more
instances are added later.

Calling CreateAssemblyClass() multiple times like the samplelapplication.c
does creates multiple single instance blocks that are not freed later
except the first one.

The right fix would be NOT to allocate the needed CipInstances en bloc and
keep the code here as it was.

Signed-off-by: Stefan Mätje <stefan.maetje@esd.eu>
Stefan Mätje hace 6 años
padre
commit
ad336e87d4
Se han modificado 1 ficheros con 1 adiciones y 6 borrados
  1. 1 6
      source/src/cip/cipmessagerouter.c

+ 1 - 6
source/src/cip/cipmessagerouter.c

@@ -286,14 +286,9 @@ void DeleteAllClasses(void) {
       { /* then free storage for the attribute array */
       { /* then free storage for the attribute array */
         CipFree(instance_to_delete->attributes);
         CipFree(instance_to_delete->attributes);
       }
       }
+      CipFree(instance_to_delete);
     }
     }
 
 
-	/*All instances memory are allocated in cip_class->instances pointer,so we have to free them in one go*/
-      if( message_router_object_to_delete->cip_class->instances != NULL)
-      {
-        CipFree(message_router_object_to_delete->cip_class->instances);
-      }
-
     /*clear meta class data*/
     /*clear meta class data*/
     CipFree(
     CipFree(
       message_router_object_to_delete->cip_class->class_instance.cip_class
       message_router_object_to_delete->cip_class->class_instance.cip_class