commit 988aaa8a45fa20dde4dfeea7756ad44a87b45702
parent ac65303b7d7c82121f4eae4ac5e025107608fb68
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date: Wed, 13 Jul 2016 14:36:34 +0200
Fix reference release order problems.
Diffstat:
8 files changed, 42 insertions(+), 52 deletions(-)
diff --git a/src/ssol_image.c b/src/ssol_image.c
@@ -27,14 +27,13 @@
static void
image_release(ref_T* ref)
{
- struct ssol_image* image;
+ struct ssol_device* dev;
+ struct ssol_image* image = CONTAINER_OF(ref, struct ssol_image, ref);
ASSERT(ref);
- image = CONTAINER_OF(ref, struct ssol_image, ref);
-
- ASSERT(image->dev && image->dev->allocator);
-
- SSOL(device_ref_put(image->dev));
+ dev = image->dev;
+ ASSERT(dev && dev->allocator);
MEM_RM(image->dev->allocator, image);
+ SSOL(device_ref_put(dev));
}
/*******************************************************************************
diff --git a/src/ssol_material.c b/src/ssol_material.c
@@ -27,14 +27,13 @@
static void
material_release(ref_T* ref)
{
- struct ssol_material* material;
+ struct ssol_device* dev;
+ struct ssol_material* material = CONTAINER_OF(ref, struct ssol_material, ref);
ASSERT(ref);
- material = CONTAINER_OF(ref, struct ssol_material, ref);
-
- ASSERT(material->dev && material->dev->allocator);
-
- SSOL(device_ref_put(material->dev));
- MEM_RM(material->dev->allocator, material);
+ dev = material->dev;
+ ASSERT(dev && dev->allocator);
+ MEM_RM(dev->allocator, material);
+ SSOL(device_ref_put(dev));
}
static INLINE res_T
diff --git a/src/ssol_object.c b/src/ssol_object.c
@@ -27,16 +27,15 @@
static void
object_release(ref_T* ref)
{
- struct ssol_object* object;
+ struct ssol_device* dev;
+ struct ssol_object* object = CONTAINER_OF(ref, struct ssol_object, ref);
ASSERT(ref);
- object = CONTAINER_OF(ref, struct ssol_object, ref);
-
- ASSERT(object->dev && object->dev->allocator);
-
+ dev = object->dev;
+ ASSERT(dev && dev->allocator);
SSOL(shape_ref_put(object->shape));
SSOL(material_ref_put(object->material));
- SSOL(device_ref_put(object->dev));
- MEM_RM(object->dev->allocator, object);
+ MEM_RM(dev->allocator, object);
+ SSOL(device_ref_put(dev));
}
static INLINE res_T
diff --git a/src/ssol_object_instance.c b/src/ssol_object_instance.c
@@ -31,19 +31,17 @@
static void
object_instance_release(ref_T* ref)
{
- struct ssol_object_instance* instance;
+ struct ssol_device* dev;
+ struct ssol_object_instance* instance
+ = CONTAINER_OF(ref, struct ssol_object_instance, ref);
ASSERT(ref);
- instance = CONTAINER_OF(ref, struct ssol_object_instance, ref);
-
- ASSERT(instance->dev && instance->dev->allocator);
-
- if (instance->object)
- SSOL(object_ref_put(instance->object));
- if (instance->image)
- SSOL(image_ref_put(instance->image));
- SSOL(device_ref_put(instance->dev));
- MEM_RM(instance->dev->allocator, instance->receiver_name);
- MEM_RM(instance->dev->allocator, instance);
+ dev = instance->dev;
+ ASSERT(dev && dev->allocator);
+ SSOL(object_ref_put(instance->object));
+ if (instance->image) SSOL(image_ref_put(instance->image));
+ MEM_RM(dev->allocator, instance->receiver_name);
+ MEM_RM(dev->allocator, instance);
+ SSOL(device_ref_put(dev));
}
/*******************************************************************************
diff --git a/src/ssol_scene.c b/src/ssol_scene.c
@@ -29,16 +29,14 @@
static void
scene_release(ref_T* ref)
{
- struct ssol_scene* scene;
struct ssol_device* dev;
+ struct ssol_scene* scene = CONTAINER_OF(ref, struct ssol_scene, ref);
ASSERT(ref);
- scene = CONTAINER_OF(ref, struct ssol_scene, ref);
- SSOL(scene_clear(scene));
dev = scene->dev;
ASSERT(dev && dev->allocator);
SSOL(scene_clear(scene));
- if (scene->scene3D) s3d_scene_ref_put(scene->scene3D);
- if (scene->sun) ssol_sun_ref_put(scene->sun);
+ if (scene->scene3D) S3D(scene_ref_put(scene->scene3D));
+ if (scene->sun) SSOL(sun_ref_put(scene->sun));
MEM_RM(dev->allocator, scene);
SSOL(device_ref_put(dev));
}
diff --git a/src/ssol_shape.c b/src/ssol_shape.c
@@ -27,16 +27,16 @@
static void
shape_release(ref_T* ref)
{
- struct ssol_shape* shape;
+ struct ssol_device* dev;
+ struct ssol_shape* shape = CONTAINER_OF(ref, struct ssol_shape, ref);
ASSERT(ref);
- shape = CONTAINER_OF(ref, struct ssol_shape, ref);
-
- ASSERT(shape->dev);
- s3d_shape_ref_put(shape->shape);
- s3d_scene_ref_put(shape->scene);
- SSOL(device_ref_put(shape->dev));
- MEM_RM(shape->dev->allocator, shape->quadric);
- MEM_RM(shape->dev->allocator, shape);
+ dev = shape->dev;
+ ASSERT(dev && dev->allocator);
+ S3D(shape_ref_put(shape->shape));
+ S3D(scene_ref_put(shape->scene));
+ MEM_RM(dev->allocator, shape->quadric);
+ MEM_RM(dev->allocator, shape);
+ SSOL(device_ref_put(dev));
}
static INLINE res_T
diff --git a/src/ssol_spectrum.c b/src/ssol_spectrum.c
@@ -28,10 +28,9 @@
static void
spectrum_release(ref_T* ref)
{
- struct ssol_spectrum* spectrum;
struct ssol_device* dev;
+ struct ssol_spectrum* spectrum = CONTAINER_OF(ref, struct ssol_spectrum, ref);
ASSERT(ref);
- spectrum = CONTAINER_OF(ref, struct ssol_spectrum, ref);
dev = spectrum->dev;
ASSERT(dev && dev->allocator);
darray_double_release(&spectrum->frequencies);
diff --git a/src/ssol_sun.c b/src/ssol_sun.c
@@ -30,14 +30,12 @@
static void
sun_release(ref_T* ref)
{
- struct ssol_sun* sun;
struct ssol_device* dev;
+ struct ssol_sun* sun = CONTAINER_OF(ref, struct ssol_sun, ref);
ASSERT(ref);
- sun = CONTAINER_OF(ref, struct ssol_sun, ref);
dev = sun->dev;
- if (sun->spectrum)
- SSOL(spectrum_ref_put(sun->spectrum));
ASSERT(dev && dev->allocator);
+ if (sun->spectrum) SSOL(spectrum_ref_put(sun->spectrum));
MEM_RM(dev->allocator, sun);
SSOL(device_ref_put(dev));
}