the behaviour of constructors for GLib data types is not specified if memory allocation fails
Submitted by Sameer D. Sahasrabuddhe
Link to original bug (#563213)
Description
Documentation Section: This bug is in the GLib reference manual, in the section titled "GLib Data Types" Although this is applicable for many (probably all) GLib data types, I'll take the example of g_array_new. The documentation says that the returned value is a pointer to a new GArray. But the documentation does not say whether the caller must check the return value to see if a NULL is returned.
Correct version: The documentation should mention the behaviour of each constructor when memory allocation fails. Specifically it should mention if the returned pointer can be a NULL, and whether an error condition is generated by the constructor.
Other information: I looked at the current sources to inspect the behaviour of g_array_new. Internally, it calls g_slice_new. It seems that g_slice_new can in fact return a NULL. But g_array_new uses the returned pointer without checking for a NULL. If my interpretation is correct, then this is not just a documentation bug ... it can also cause a segmentation fault in g_array_new and other such constructors.
Version: 2.16.x