From 0d53158553fa864464c34af144609b654479360c Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Tue, 7 Feb 2006 02:02:33 +0100 Subject: [PATCH] NET: Ensure that move_download sets new->conn to NULL when in result state When in result state the connection might already have been freed. --- src/network/connection.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/network/connection.c b/src/network/connection.c index f2c59a08..52b57620 100644 --- a/src/network/connection.c +++ b/src/network/connection.c @@ -1021,7 +1021,7 @@ void move_download(struct download *old, struct download *new, enum connection_priority newpri) { - struct connection *conn = old->conn; + struct connection *conn; assert(old); @@ -1029,7 +1029,9 @@ move_download(struct download *old, struct download *new, * example the file protocol loads it's object immediately. This is * catched by the result state check below. */ - new->conn = old->conn; + conn = old->conn; + + new->conn = conn; new->cached = old->cached; new->prev_error = old->prev_error; new->progress = old->progress; @@ -1037,8 +1039,12 @@ move_download(struct download *old, struct download *new, new->pri = newpri; if (is_in_result_state(old->state)) { - if (new->callback) + /* Ensure that new->conn is always "valid", that is NULL if the + * connection has been detached and non-NULL otherwise. */ + if (new->callback) { + new->conn = NULL; new->callback(new, new->data); + } return; }