gjs tries to free NULL error returned from C function
System information
What is your operating system and version? macOS 10.15.6
What is your version of GJS? 1.64.4 (homebrew package)
Bug information
Steps to reproduce
I've written a library which includes the following function:
/**
* htsp_message_to_error:
* @msg: (transfer none):
* Returns: (transfer full) (nullable):
*
* Makes a GError from a message with an error field. Returns NULL if the
* message doesn't have an error field.
*/
GError *htsp_message_to_error(const GstStructure *msg);
Current behaviour
What happened that made it evident there was a problem?
When I called the above function from gjs I saw a warning on the console that it had tried to call g_error_free() on a NULL pointer, and worked out that the problem call was in gjs, not my code. Sorry, I didn't keep an exact log of the warning, but it was definitely about g_error_free and NULL. I got a backtrace by using G_MESSAGES_DEBUG=all, but it's a bit limited. If you need something more detailed I can try rebuilding gjs with debugging symbols on Linux and using the spidermonkey debugger.
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libglib-2.0.0.dylib 0x0000000102534d2e g_logv + 1070
1 libglib-2.0.0.dylib 0x00000001025348e2 g_log + 130
2 libgjs.0.dylib 0x000000010217ae0a gjs_g_arg_release_internal(JSContext*, GITransfer, _GIBaseInfoStub*, GITypeTag, _GIArgument*) + 186
3 libgjs.0.dylib 0x000000010217ad3d gjs_g_argument_release(JSContext*, GITransfer, _GIBaseInfoStub*, _GIArgument*) + 77
4 libgjs.0.dylib 0x00000001021a3728 gjs_invoke_c_function(JSContext*, Function*, JS::Handle<JSObject*>, JS::HandleValueArray const&, mozilla::Maybe<JS::MutableHandle<JS::Value> >, _GIArgument*) + 8088
5 libgjs.0.dylib 0x00000001021a520d function_call(JSContext*, unsigned int, JS::Value*) + 765
6 libmozjs-68.dylib 0x00000001028b6781 js::InternalCallOrConstruct(JSContext*, JS::CallArgs const&, js::MaybeConstruct) + 2161