pwmt / zathura

Document viewer
https://pwmt.org/projects/zathura
zlib License
2.05k stars 142 forks source link

Clean up cairo error handling - [merged] #539

Closed sebastinas closed 5 months ago

sebastinas commented 1 year ago

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() 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.

sebastinas commented 1 year ago

mentioned in commit a1b93ff18080eeff2f07c8661040eea19692a859