diff --git a/kitty/graphics.c b/kitty/graphics.c index 09f651782..5205331a7 100644 --- a/kitty/graphics.c +++ b/kitty/graphics.c @@ -42,7 +42,7 @@ grman_realloc(GraphicsManager *old, index_type lines, index_type columns) { } else { self->images_capacity = old->images_capacity; self->images = old->images; self->image_count = old->image_count; old->images = NULL; - grman_free(old); + Py_DECREF(old); } return self; } @@ -64,12 +64,13 @@ free_image(Image *img) { free_load_data(&(img->load_data)); } -GraphicsManager* -grman_free(GraphicsManager* self) { - for (size_t i = 0; i < self->image_count; i++) free_image(self->images + i); - free(self->images); +static void +dealloc(GraphicsManager* self) { + if (self->images) { + for (size_t i = 0; i < self->image_count; i++) free_image(self->images + i); + free(self->images); + } Py_TYPE(self)->tp_free((PyObject*)self); - return NULL; } static size_t internal_id_counter = 1; @@ -426,11 +427,6 @@ new(PyTypeObject UNUSED *type, PyObject *args, PyObject UNUSED *kwds) { return ans; } -static void -dealloc(GraphicsManager* self) { - grman_free(self); -} - static inline PyObject* image_as_dict(Image *img) { #define U(x) #x, img->x diff --git a/kitty/graphics.h b/kitty/graphics.h index 9d85357e8..b0cb3c7d9 100644 --- a/kitty/graphics.h +++ b/kitty/graphics.h @@ -49,5 +49,4 @@ PyTypeObject GraphicsManager_Type; GraphicsManager* grman_realloc(GraphicsManager *, index_type lines, index_type columns); void grman_clear(GraphicsManager*); -GraphicsManager* grman_free(GraphicsManager*); const char* grman_handle_command(GraphicsManager *self, const GraphicsCommand *g, const uint8_t *payload); diff --git a/kitty/screen.c b/kitty/screen.c index f890fe196..8b8d7d5d2 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -213,8 +213,7 @@ static void dealloc(Screen* self) { pthread_mutex_destroy(&self->read_buf_lock); pthread_mutex_destroy(&self->write_buf_lock); - if (self->main_grman) { self->main_grman = grman_free(self->main_grman); } - if (self->alt_grman) { self->alt_grman = grman_free(self->alt_grman); } + Py_CLEAR(self->grman); Py_CLEAR(self->alt_grman); PyMem_RawFree(self->write_buf); Py_CLEAR(self->callbacks); Py_CLEAR(self->test_child);