COIN-OR::LEMON - Graph Library

Changeset 295:7c796c1cf1b0 in lemon-1.0 for lemon/lgf_writer.h


Ignore:
Timestamp:
10/05/08 21:09:01 (16 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Fix memory leak hazard

If the constructor throws an exception, it should deallocate each
dynamically allocated memory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lgf_writer.h

    r294 r295  
    464464      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    465465        _skip_nodes(false), _skip_arcs(false) {
    466       if (!(*_os)) throw IoError("Cannot write file", fn);
     466      if (!(*_os)) {
     467        delete _os;
     468        throw IoError("Cannot write file", fn);
     469      }
    467470    }
    468471
     
    474477      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    475478        _skip_nodes(false), _skip_arcs(false) {
    476       if (!(*_os)) throw IoError("Cannot write file", fn);
     479      if (!(*_os)) {
     480        delete _os;
     481        throw IoError("Cannot write file", fn);
     482      }
    477483    }
    478484
     
    10251031      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
    10261032        _skip_nodes(false), _skip_edges(false) {
    1027       if (!(*_os)) throw IoError("Cannot write file", fn);
     1033      if (!(*_os)) {
     1034        delete _os;
     1035        throw IoError("Cannot write file", fn);
     1036      }
    10281037    }
    10291038
     
    10351044      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
    10361045        _skip_nodes(false), _skip_edges(false) {
    1037       if (!(*_os)) throw IoError("Cannot write file", fn);
     1046      if (!(*_os)) {
     1047        delete _os;
     1048        throw IoError("Cannot write file", fn);
     1049      }
    10381050    }
    10391051
     
    15881600    SectionWriter(const std::string& fn)
    15891601      : _os(new std::ofstream(fn.c_str())), local_os(true) {
    1590       if (!(*_os)) throw IoError("Cannot write file", fn);
     1602      if (!(*_os)) {
     1603        delete _os;
     1604        throw IoError("Cannot write file", fn);
     1605      }
    15911606    }
    15921607
     
    15961611    SectionWriter(const char* fn)
    15971612      : _os(new std::ofstream(fn)), local_os(true) {
    1598       if (!(*_os)) throw IoError("Cannot write file", fn);
     1613      if (!(*_os)) {
     1614        delete _os;
     1615        throw IoError("Cannot write file", fn);
     1616      }
    15991617    }
    16001618
Note: See TracChangeset for help on using the changeset viewer.