* [PATCH obexd] gobex: fix transfer search in transfer_complete
@ 2011-12-13 16:21 Mikel Astiz
2011-12-14 10:21 ` Luiz Augusto von Dentz
2011-12-15 11:33 ` Johan Hedberg
0 siblings, 2 replies; 3+ messages in thread
From: Mikel Astiz @ 2011-12-13 16:21 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Mikel Astiz
The previous approach searched the transfer pointer itself, assuming
that the transfers has not been modified if the pointer is in the list.
However the callback could have removed the transfer and registered
another one, which can eventually point to the same memory location.
This is solved by looking for the transfer id instead of the pointer.
---
gobex/gobex-transfer.c | 30 +++++++++++++++++++-----------
1 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/gobex/gobex-transfer.c b/gobex/gobex-transfer.c
index f5222cd..692d713 100644
--- a/gobex/gobex-transfer.c
+++ b/gobex/gobex-transfer.c
@@ -77,14 +77,30 @@ static void transfer_free(struct transfer *transfer)
g_free(transfer);
}
+static struct transfer *find_transfer(guint id)
+{
+ GSList *l;
+
+ for (l = transfers; l != NULL; l = g_slist_next(l)) {
+ struct transfer *t = l->data;
+ if (t->id == id)
+ return t;
+ }
+
+ return NULL;
+}
+
static void transfer_complete(struct transfer *transfer, GError *err)
{
- g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
+ guint id = transfer->id;
+
+ g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);
transfer->complete_func(transfer->obex, err, transfer->user_data);
/* Check if the complete_func removed the transfer */
- if (g_slist_find(transfers, transfer) == NULL)
+ if (find_transfer(id) == NULL)
return;
+
transfer_free(transfer);
}
@@ -425,7 +441,6 @@ guint g_obex_get_req_pkt(GObex *obex, GObexPacket *req,
transfer = transfer_new(obex, G_OBEX_OP_GET, complete_func, user_data);
transfer->data_consumer = data_func;
-
transfer->req_id = g_obex_send_req(obex, req, FIRST_PACKET_TIMEOUT,
transfer_response, transfer, err);
if (transfer->req_id == 0) {
@@ -573,17 +588,10 @@ guint g_obex_get_rsp(GObex *obex, GObexDataProducer data_func,
gboolean g_obex_cancel_transfer(guint id)
{
struct transfer *transfer = NULL;
- GSList *l;
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);
- for (l = transfers; l != NULL; l = g_slist_next(l)) {
- struct transfer *t = l->data;
- if (t->id == id) {
- transfer = t;
- break;
- }
- }
+ transfer = find_transfer(id);
if (transfer == NULL)
return FALSE;
--
1.7.6.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH obexd] gobex: fix transfer search in transfer_complete
2011-12-13 16:21 [PATCH obexd] gobex: fix transfer search in transfer_complete Mikel Astiz
@ 2011-12-14 10:21 ` Luiz Augusto von Dentz
2011-12-15 11:33 ` Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2011-12-14 10:21 UTC (permalink / raw)
To: Mikel Astiz; +Cc: linux-bluetooth
Hi Mikel,
On Tue, Dec 13, 2011 at 6:21 PM, Mikel Astiz <mikel.astiz@bmw-carit.de> wrote:
> The previous approach searched the transfer pointer itself, assuming
> that the transfers has not been modified if the pointer is in the list.
> However the callback could have removed the transfer and registered
> another one, which can eventually point to the same memory location.
>
> This is solved by looking for the transfer id instead of the pointer.
> ---
Ack.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH obexd] gobex: fix transfer search in transfer_complete
2011-12-13 16:21 [PATCH obexd] gobex: fix transfer search in transfer_complete Mikel Astiz
2011-12-14 10:21 ` Luiz Augusto von Dentz
@ 2011-12-15 11:33 ` Johan Hedberg
1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2011-12-15 11:33 UTC (permalink / raw)
To: Mikel Astiz; +Cc: linux-bluetooth
Hi Mikel,
On Tue, Dec 13, 2011, Mikel Astiz wrote:
> The previous approach searched the transfer pointer itself, assuming
> that the transfers has not been modified if the pointer is in the list.
> However the callback could have removed the transfer and registered
> another one, which can eventually point to the same memory location.
>
> This is solved by looking for the transfer id instead of the pointer.
> ---
> gobex/gobex-transfer.c | 30 +++++++++++++++++++-----------
> 1 files changed, 19 insertions(+), 11 deletions(-)
Applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-15 11:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-13 16:21 [PATCH obexd] gobex: fix transfer search in transfer_complete Mikel Astiz
2011-12-14 10:21 ` Luiz Augusto von Dentz
2011-12-15 11:33 ` Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).