Some of the code was comparing the return value of functions like cairo_create() and cairo_surface_create() against NULL which is not correct. As per the documentation of cairo_create():
(...) This function never returns NULL. If memory cannot be allocated, a special cairo_t object will be returned on which cairo_status() returns CAIRO_STATUS_NO_MEMORY. (...)
This MR aims to make error checking consistent upon calls to native cairo functions. Do note however, that some of the code in Zathura relies on setting cairo_surface_t objects to NULL. E.g. cb_menu_image_copy() calls zathura_page_image_get_cairo() which calls into the plugin function (pdf_)page_image_get_cairo() which returns NULL in its error path. There is no memory leak because plugins correctly deallocate memory in their error paths, but this behavior might be error-prone due to these inconsistencies in error handling between cairo and Zathura.
Anyway, now that all the code that creates cairos and surfaces uses cairo_*status() functions new code should tend to do the same.
On GitLab by @marcoe on Jul 4, 2023, 14:49
Merges cleanup-cairo -> develop
Some of the code was comparing the return value of functions like
cairo_create()
andcairo_surface_create()
against NULL which is not correct. As per the documentation ofcairo_create()
:This MR aims to make error checking consistent upon calls to native cairo functions. Do note however, that some of the code in Zathura relies on setting
cairo_surface_t
objects to NULL. E.g.cb_menu_image_copy()
callszathura_page_image_get_cairo()
which calls into the plugin function(pdf_)page_image_get_cairo()
which returns NULL in its error path. There is no memory leak because plugins correctly deallocate memory in their error paths, but this behavior might be error-prone due to these inconsistencies in error handling between cairo and Zathura.Anyway, now that all the code that creates cairos and surfaces uses
cairo_*status()
functions new code should tend to do the same.