Fix a couple of resource leaks on exceptions being thrown.
authorCarl Hetherington <cth@carlh.net>
Tue, 16 Jul 2013 12:02:54 +0000 (13:02 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 16 Jul 2013 12:02:54 +0000 (13:02 +0100)
src/lib/scp_dcp_job.cc

index 8cde44f0258a2d65ad8a4a44fa437b653f216c2d..528d393a36d73e559e0ca8b9d45b1e973ea87a3a 100644 (file)
@@ -179,11 +179,13 @@ SCPDCPJob::run ()
                        int const t = min (to_do, buffer_size);
                        size_t const read = fread (buffer, 1, t, f);
                        if (read != size_t (t)) {
+                               fclose (f);
                                throw ReadFileError (boost::filesystem::path (*i).string());
                        }
                        
                        r = ssh_scp_write (sc.scp, buffer, t);
                        if (r != SSH_OK) {
+                               fclose (f);
                                throw NetworkError (String::compose (_("Could not write to remote file (%1)"), ssh_get_error (ss.session)));
                        }
                        to_do -= t;