Skip to content

graphics: Don't free a const version_string

Simon McVittie requested to merge wip/smcv/graphics-ownership into master

On the wflinfo code path, the version string is "borrowed" from the JSON data structure, but on the vulkaninfo code path, it is built up from multiple fields and needs to be freed.

Instead of having a variable that is sometimes "borrowed" and sometimes "owned" and a boolean to indicate which it is, let's have a separate variable new_version_string that is always "owned" (but possibly NULL), then make version_string a "borrowed" pointer to either the wflinfo JSON or new_version_string.

Signed-off-by: Simon McVittie smcv@collabora.com


I'm not sure what the difference is between our compiler versions and compiler arguments, but mine has -Werror=discarded-qualifiers and failed on this.

This is a pattern that I often use. As a good rule of thumb, if you look at any variable that represents a resource (typically pointers, but also file descriptors and other handles), you should be able to say "this is owned" or "this is borrowed" without any ambiguity.

Merge request reports

Loading