Copilot commented on code in PR #50401:
URL: https://github.com/apache/arrow/pull/50401#discussion_r3532997745
##########
c_glib/arrow-flight-glib/server.cpp:
##########
@@ -1236,6 +1251,14 @@ gaflight_server_listen(GAFlightServer *server,
{
auto flight_server = gaflight_servable_get_raw(GAFLIGHT_SERVABLE(server));
const auto flight_options = gaflight_server_options_get_raw(options);
+ auto priv = GAFLIGHT_SERVER_GET_PRIVATE(server);
+ if (priv->options != options) {
+ g_object_ref(priv->options);
+ if (priv->options) {
+ g_object_unref(priv->options);
+ }
+ priv->options = options;
+ }
Review Comment:
The ref/unref logic in `gaflight_server_listen()` is wrong and can crash: it
calls `g_object_ref(priv->options)` even when `priv->options` is
null/uninitialized, and it never refs the new `options`. This defeats the
intent of keeping `options` alive (and may dereference NULL).
##########
c_glib/arrow-flight-glib/server.cpp:
##########
@@ -1196,6 +1197,19 @@ gaflight_server_servable_get_raw(GAFlightServable
*servable)
}
G_BEGIN_DECLS
+static void
+gaflight_server_dispose(GObject *object)
+{
+ auto priv = GAFLIGHT_SERVER_GET_PRIVATE(object);
+
+ if (priv->options) {
+ g_object_unref(priv->options);
+ priv->options = nullptr;
+ }
Review Comment:
`priv->options` is never initialized, but `dispose()` unrefs it. As written,
a newly constructed instance may have an indeterminate `priv->options` value
and `g_object_unref()` could crash. Initialize the pointer to `nullptr` in
`gaflight_server_init()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]