Fix: bt_stream_common_finalize(): check `stream->destroy_listeners`
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 16 Apr 2018 22:47:39 +0000 (18:47 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 2 May 2019 04:05:45 +0000 (00:05 -0400)
Issue
=====
In bt_stream_common_finalize(), `stream->destroy_listeners` is not
checked before calling iterating the array to call the destroy
listeners. This can happen if the stream is partially initialized and
then destroyed when there's an error in bt_stream_common_initialize().

Solution
========
Check `stream->destroy_listeners` before iterating the destroy listener
array.

Known drawbacks
===============
None.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
lib/ctf-ir/stream.c

index 2787230c873170bbd454eee8dd90060b0617a45e..70030454d6956c3cdbf68668ce5dc118e23f80d1 100644 (file)
@@ -52,14 +52,16 @@ void bt_stream_common_finalize(struct bt_stream_common *stream)
                stream, bt_stream_common_get_name(stream));
 
        /* Call destroy listeners in reverse registration order */
-       for (i = stream->destroy_listeners->len - 1; i >= 0; i--) {
-               struct bt_stream_common_destroy_listener *listener =
-                       &g_array_index(stream->destroy_listeners,
-                               struct bt_stream_common_destroy_listener, i);
-
-               BT_LOGD("Calling destroy listener: func=%p, data=%p, index=%d",
-                       listener->func, listener->data, i);
-               listener->func(stream, listener->data);
+       if (stream->destroy_listeners) {
+               for (i = stream->destroy_listeners->len - 1; i >= 0; i--) {
+                       struct bt_stream_common_destroy_listener *listener =
+                               &g_array_index(stream->destroy_listeners,
+                                       struct bt_stream_common_destroy_listener, i);
+
+                       BT_LOGD("Calling destroy listener: func=%p, data=%p, index=%d",
+                               listener->func, listener->data, i);
+                       listener->func(stream, listener->data);
+               }
        }
 
        if (stream->name) {
This page took 0.025032 seconds and 4 git commands to generate.