[gparted] Move initial clearing of output capture buffers into PipeCapture class (#777973)



commit a233e30efeb80c72b7e9943ee7f615aa006c012f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date:   Sat Mar 4 16:38:26 2017 +0000

    Move initial clearing of output capture buffers into PipeCapture class (#777973)
    
    Seems more logical to initially clear the output capture buffer in a
    single location in the PipeCapture class which reads the command output
    into said buffer, rather than each calling site before the PipeCapture
    objects are constructed.
    
    Bug 777973 - Segmentation fault on bad disk

 src/FileSystem.cc  |    2 --
 src/PipeCapture.cc |    1 +
 src/Utils.cc       |    2 --
 3 files changed, 1 insertions(+), 4 deletions(-)
---
diff --git a/src/FileSystem.cc b/src/FileSystem.cc
index 9fc6ce2..79a52ee 100644
--- a/src/FileSystem.cc
+++ b/src/FileSystem.cc
@@ -133,8 +133,6 @@ int FileSystem::execute_command_internal( const Glib::ustring & command, Operati
        fcntl( out, F_SETFL, O_NONBLOCK );
        fcntl( err, F_SETFL, O_NONBLOCK );
        Glib::signal_child_watch().connect( sigc::mem_fun( *this, &FileSystem::store_exit_status ), pid );
-       output.clear();
-       error.clear();
        pipecount = 2;
        PipeCapture outputcapture( out, output );
        PipeCapture errorcapture( err, error );
diff --git a/src/PipeCapture.cc b/src/PipeCapture.cc
index 5690f0f..b89df72 100644
--- a/src/PipeCapture.cc
+++ b/src/PipeCapture.cc
@@ -25,6 +25,7 @@ namespace GParted {
 PipeCapture::PipeCapture( int fd, Glib::ustring &string ) : buff( string ),
                                                             linestart( 0 ), cursor( 0 ), lineend( 0 )
 {
+       buff.clear();
        // tie fd to string
        // make channel
        channel = Glib::IOChannel::create_from_fd( fd );
diff --git a/src/Utils.cc b/src/Utils.cc
index a429950..811a374 100644
--- a/src/Utils.cc
+++ b/src/Utils.cc
@@ -601,8 +601,6 @@ int Utils::execute_command( const Glib::ustring & command,
        fcntl( out, F_SETFL, O_NONBLOCK );
        fcntl( err, F_SETFL, O_NONBLOCK );
        g_child_watch_add( pid, _store_exit_status, &status );
-       output.clear();
-       error.clear();
        //Lock mutex so we have time to setup pipecapture for output and error streams
        //  before connecting the input/output signal handler
        if( !status.foreground )


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]