Allow NULL to be passed to destructors

In this case, the destructor will be a no-op. This is similar to free(3)'s
behavior and allows to omit a NULL check for callers.
This commit is contained in:
Simon Ser 2019-12-31 20:46:08 +01:00
parent 7286146341
commit cfeee41ec1
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 12 additions and 0 deletions

View file

@ -70,6 +70,10 @@ void liftoff_device_destroy(struct liftoff_device *device)
{
struct liftoff_plane *plane, *tmp;
if (device == NULL) {
return;
}
close(device->drm_fd);
liftoff_list_for_each_safe(plane, tmp, &device->planes, link) {
plane_destroy(plane);

View file

@ -19,6 +19,10 @@ struct liftoff_layer *liftoff_layer_create(struct liftoff_output *output)
void liftoff_layer_destroy(struct liftoff_layer *layer)
{
if (layer == NULL) {
return;
}
layer->output->layers_changed = true;
if (layer->plane != NULL) {
layer->plane->layer = NULL;

View file

@ -37,6 +37,10 @@ struct liftoff_output *liftoff_output_create(struct liftoff_device *device,
void liftoff_output_destroy(struct liftoff_output *output)
{
if (output == NULL) {
return;
}
liftoff_list_remove(&output->link);
free(output);
}