From 5acdc773a649e8fe104cc0e3647b568280c58f05 Mon Sep 17 00:00:00 2001 From: Francis Deslauriers Date: Wed, 4 Jul 2012 09:15:25 -0400 Subject: [PATCH 1/1] Several fixes for bt_iter_pos related functions Add verification so we free the array only if iterator is of type BT_SEEK_RESTORE Add return statement at the end of case Set type of bt_iter_pos returned by bt_iter_get_pos [ Mathieu Desnoyers edit: check the iter_pos->type before the restore pointer in bt_iter_free_pos. The && operator is a sequence point, so the first check is done before the second. Since we might not be using the union for restore if type != BT_SEEK_RESTORE, check the type first before accessing the (possibly wrong) union field. ] Signed-off-by: Francis Deslauriers Signed-off-by: Julien Desfossez Signed-off-by: Mathieu Desnoyers --- lib/iterator.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/iterator.c b/lib/iterator.c index 52ec0649..6b1a6d2a 100644 --- a/lib/iterator.c +++ b/lib/iterator.c @@ -81,7 +81,7 @@ void bt_iter_free_pos(struct bt_iter_pos *iter_pos) if (!iter_pos) return; - if (iter_pos->u.restore) { + if (iter_pos->type == BT_SEEK_RESTORE && iter_pos->u.restore) { if (iter_pos->u.restore->stream_saved_pos) { g_array_free( iter_pos->u.restore->stream_saved_pos, @@ -242,6 +242,7 @@ int bt_iter_set_pos(struct bt_iter *iter, const struct bt_iter_pos *iter_pos) if (ret) goto error; } + return 0; case BT_SEEK_TIME: tc = iter->ctx->tc; @@ -339,6 +340,7 @@ struct bt_iter_pos *bt_iter_get_pos(struct bt_iter *iter) int i, stream_class_id, stream_id; pos = g_new0(struct bt_iter_pos, 1); + pos->type = BT_SEEK_RESTORE; pos->u.restore = g_new0(struct bt_saved_pos, 1); pos->u.restore->tc = tc; pos->u.restore->stream_saved_pos = g_array_new(FALSE, TRUE, -- 2.34.1