@@ -83,15 +83,18 @@ static struct transfer *find_transfer(guint id)
static void transfer_complete(struct transfer *transfer, GError *err)
{
- guint id = transfer->id;
+ if (!g_slist_find(transfers, transfer))
+ return;
- g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", id);
+ transfer->req_id = 0;
+ g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
if (err) {
/* No further tx must be performed */
g_obex_drop_tx_queue(transfer->obex);
}
+ guint id = transfer->id;
transfer->complete_func(transfer->obex, err, transfer->user_data);
/* Check if the complete_func removed the transfer */
if (find_transfer(id) == NULL)
@@ -106,9 +109,6 @@ static void transfer_abort_response(GObex *obex, GError *err, GObexPacket *rsp,
struct transfer *transfer = user_data;
g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
-
- transfer->req_id = 0;
-
/* Intentionally override error */
err = g_error_new(G_OBEX_ERROR, G_OBEX_ERROR_CANCELLED,
"Operation was aborted");
@@ -186,11 +186,6 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
gboolean rspcode, final;
guint id;
- g_obex_debug(G_OBEX_DEBUG_TRANSFER, "transfer %u", transfer->id);
-
- id = transfer->req_id;
- transfer->req_id = 0;
-
if (err != NULL) {
transfer_complete(transfer, err);
return;
@@ -203,6 +198,9 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
goto failed;
}
+ if (!g_slist_find(transfers, transfer))
+ return;
+
if (transfer->opcode == G_OBEX_OP_GET) {
handle_get_body(transfer, rsp, &err);
if (err != NULL)
@@ -222,8 +220,6 @@ static void transfer_response(GObex *obex, GError *err, GObexPacket *rsp,
req = g_obex_packet_new(transfer->opcode, TRUE,
G_OBEX_HDR_INVALID);
} else {
- /* Keep id since request still outstanting */
- transfer->req_id = id;
return;
}