stream: don't close underlying socket when creating a stream from it
authorMartin Willi <martin@revosec.ch>
Tue, 2 Jul 2013 12:04:51 +0000 (14:04 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 18 Jul 2013 14:00:29 +0000 (16:00 +0200)
src/libstrongswan/networking/streams/stream_service.c

index 1b06e1e..c2681af 100644 (file)
@@ -109,7 +109,10 @@ static void destroy_async_data(async_data_t *data)
        this->condvar->signal(this->condvar);
        this->mutex->unlock(this->mutex);
 
-       close(data->fd);
+       if (data->fd != -1)
+       {
+               close(data->fd);
+       }
        free(data);
 }
 
@@ -123,6 +126,8 @@ static job_requeue_t accept_async(async_data_t *data)
        stream = stream_create_from_fd(data->fd);
        if (stream)
        {
+               /* FD is now owned by stream, don't close it during cleanup */
+               data->fd = -1;
                thread_cleanup_push((void*)stream->destroy, stream);
                thread_cleanup_pop(!data->cb(data->data, stream));
        }