From 1b8cfed5c880d1fdc9c0d71412d918b14aebabb5 Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 14 Apr 2016 19:25:26 -0700 Subject: [PATCH] writer: use dup()d fd when creating reader Readers can share the file-offset in the file-descriptor table, but should really have their own fd that they can close(). --- lib/sp-capture-writer.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/sp-capture-writer.c b/lib/sp-capture-writer.c index 794fa383..b416c578 100644 --- a/lib/sp-capture-writer.c +++ b/lib/sp-capture-writer.c @@ -933,10 +933,19 @@ SpCaptureReader * sp_capture_writer_create_reader (SpCaptureWriter *self, GError **error) { + int copy; + g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (self->fd != -1, NULL); - return sp_capture_reader_new_from_fd (self->fd, error); + /* + * We don't care about the write position, since the reader + * uses positioned reads. + */ + if (-1 == (copy = dup (self->fd))) + return NULL; + + return sp_capture_reader_new_from_fd (copy, error); } /**