Ticket #5117: libs_libmythtv_fifowriter.cpp-always-check-fd-from-open.patch

File libs_libmythtv_fifowriter.cpp-always-check-fd-from-open.patch, 895 bytes (added by Erik Hovland <erik@…>, 12 years ago)

check open() fd before calling write() with given fd

  • libs/libmythtv/fifowriter.cpp

    When calling open, you might get a -1 for a file descriptor. Check it
    
    From: Erik Hovland <erik@hovland.org>
    
    before handing the file descriptor off to write().
    ---
    
     libs/libmythtv/fifowriter.cpp |    3 ++-
     1 files changed, 2 insertions(+), 1 deletions(-)
    
    diff --git a/libs/libmythtv/fifowriter.cpp b/libs/libmythtv/fifowriter.cpp
    index 3f4a518..9d6fabe 100644
    a b void FIFOWriter::FIFOWriteThread(void) 
    141141            break;
    142142        if (fd == -1)
    143143            fd = open(filename[id].ascii(), O_WRONLY| O_SYNC);
    144         write(fd, fb_outptr[id]->data, fb_outptr[id]->blksize);
     144        if (fd >= 0)
     145            write(fd, fb_outptr[id]->data, fb_outptr[id]->blksize);
    145146        pthread_mutex_lock(&fifo_lock[id]);
    146147        fb_outptr[id] = fb_outptr[id]->next;
    147148        pthread_cond_signal(&full_cond[id]);