Changeset 140 for trunk/lib


Ignore:
Timestamp:
Aug 4, 2006, 2:12:11 AM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses #56. Fixed freeing of resources on svn error.

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/SVN.cc

    r138 r140  
    2525
    2626#include <string>
     27
     28#include <apr_allocator.h>
    2729#include <apr_hash.h>
    2830#include <svn_cmdline.h>
     
    6466    // initialize the repository access library
    6567    if ((err=svn_ra_initialize(pool_))) {
    66       // destroys pool and clears err
    67       svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
    68       apr_allocator_destroy(allocator_);
     68      cleanup_failed_initialization(err);
    6969      throw SVNException("SVN(void): svn_ra_initialize failed");
    7070    }
     
    7575    // stuff (compare with the svn binary).
    7676    if ((err=svn_config_ensure(NULL, pool_))) {
    77       // destroys pool and clears err
    78       svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
    79       apr_allocator_destroy(allocator_);
     77      cleanup_failed_initialization(err);
    8078      throw SVNException("SVN(void): svn_config_ensure failed");
    8179    }
     
    8381    // create a client context object
    8482    if ((err=svn_client_create_context(&context_, pool_))) {
    85       // destroys pool and clears err
    86       svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
    87       apr_allocator_destroy(allocator_);
     83      cleanup_failed_initialization(err);
    8884      throw SVNException("SVN(void): svn_client_create_context failed");
    8985    }
    9086
    9187    if ((err=svn_config_get_config(&(context_->config), NULL, pool_))) {
    92       // destroys pool and clears err
    93       svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
    94       apr_allocator_destroy(allocator_);
     88      cleanup_failed_initialization(err);
    9589      throw SVNException("SVN(void): svn_config_get_config failed");
    9690    }
     
    10498                                          context_->cancel_func,
    10599                                          context_->cancel_baton, pool_))) {
    106       svn_handle_error2(err, stderr, false, "svnstat: ");
    107       svn_error_clear(err);
     100      cleanup_failed_initialization(err);
    108101      throw SVNException("SVN(void): svn_cmdline_setup_auth_baton failed");
    109102    }
     
    113106  SVN::~SVN(void)
    114107  {
     108    if (adm_access_)
     109      svn_error_clear(svn_wc_adm_close(adm_access_));
    115110    svn_pool_destroy(pool_);
    116111    apr_allocator_destroy(allocator_);
     
    144139
    145140
     141  void SVN::client_info(const std::string& path, svn_info_receiver_t receiver,
     142                        void *baton)
     143  {
     144    if (svn_error_t *err=svn_client_info(path.c_str(), NULL, NULL, receiver,
     145                                         baton, false, context_, pool_)) {
     146      svn_handle_error2(err, stderr, false, "svnstat: ");
     147      svn_error_clear(err);
     148      throw SVNException("repository: svn_client_info failed");
     149    }
     150  }
     151
     152
    146153  std::vector<std::string> SVN::commit_dates(const std::string& path)
    147154  {
     
    162169    // call below, not needed for the functionality here.
    163170    if ((err=svn_ra_get_latest_revnum(ra_session_,&(head.value.number),pool_))) {
    164       svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     171      svn_handle_error2(err, stderr, false, "svnstat: ");
     172      svn_error_clear(err);
    165173      throw SVNException("commit_dates: svn_ra_get_latest_revnum failed");
    166174    }
     
    173181                             log_message_receiver, static_cast<void*>(&lb),
    174182                             context_, pool_))) {
    175       svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     183      svn_handle_error2(err, stderr, false, "svnstat: ");
     184      svn_error_clear(err);
    176185      throw SVNException("commit_dates: svn_client_log3 failed");
    177186    }
    178187    return lb.commit_dates;
     188  }
     189
     190
     191  void SVN::cleanup_failed_initialization(svn_error_t *err)
     192  {
     193    svn_handle_error2(err,stderr,false,"svnstat:");
     194    svn_error_clear(err);
     195    svn_pool_destroy(pool_);
     196    apr_allocator_destroy(allocator_);
    179197  }
    180198
     
    196214  void SVN::setup_ra_session(const std::string& path) {
    197215    // get a session to the repository
    198     if (svn_client_open_ra_session(&ra_session_, path.c_str(), context_,pool_)) {
    199       // Jari, should the error space be cleared?
     216    if (svn_error_t *err=svn_client_open_ra_session(&ra_session_, path.c_str(),
     217                                                    context_,pool_)) {
     218      svn_handle_error2(err,stderr,false,"svnstat:");
     219      svn_error_clear(err);
    200220      throw SVNException("setup_ra_session: svn_client_open_ra_session failed");
    201221    }
     
    206226  {
    207227    // Set up svn administration area access. The whole structure is
    208     // setup, maybe this should not be done?
     228    // setup, maybe this is unnecessary?
    209229    const char* canonical_path=svn_path_internal_style(path.c_str(), pool_);
    210     if (svn_wc_adm_open3(&adm_access_, NULL, canonical_path, false, -1,
    211                          context_->cancel_func,context_->cancel_baton, pool_))
    212       // Jari, should the error space be cleared?
     230    if (svn_error_t *err=svn_wc_adm_open3(&adm_access_, NULL, canonical_path,
     231                                          false, -1, context_->cancel_func,
     232                                          context_->cancel_baton, pool_)) {
     233      svn_handle_error2(err,stderr,false,"svnstat:");
     234      svn_error_clear(err);
    213235      throw SVNException("setup_wc_adm_access: svn_wc_adm_open3 failed");
     236    }
    214237  }
    215238
     
    218241  {
    219242    svn_wc_status2_t* status=NULL;
    220     if (svn_wc_status2(&status,svn_path_internal_style(path.c_str(), pool_),
    221                        adm_access_, pool_))
     243    if (svn_error_t *err=
     244        svn_wc_status2(&status,svn_path_internal_style(path.c_str(), pool_),
     245                       adm_access_, pool_)) {
     246      svn_handle_error2(err,stderr,false,"svnstat:");
     247      svn_error_clear(err);
    222248      throw SVNException("version_controlled(): svn_config_get_config failed");
     249    }
    223250
    224251    if ((status->text_status==svn_wc_status_none) ||
  • trunk/lib/SVN.h

    r138 r140  
    3939
    4040  ///
    41   /// If something goes wrong in the use of the SVN class, a
    42   /// SVNException is thrown.
     41  /// If something goes wrong in the use of the different SVN classes,
     42  /// an SVNException is thrown.
    4343  ///
    4444  struct SVNException : public std::runtime_error
     
    106106    /// @see Subversion API documentation, SVNinfo
    107107    ///
    108     inline void client_info(const std::string& path,
    109                             svn_info_receiver_t receiver, void *baton)
    110     {
    111       if (svn_client_info(path.c_str(), NULL, NULL, receiver, baton, false,
    112                           context_, pool_))
    113         throw SVNException("repository: svn_client_info failed");
    114     }
     108    void client_info(const std::string& path, svn_info_receiver_t receiver,
     109                     void *baton);
    115110
    116111    ///
     
    140135    /// underlying subversion API calls.
    141136    ///
    142     /// @todo Make sure that the underlying constructor performs
    143     /// proper cleanup before throwing an exception.
    144     ///
    145137    static SVN* instance(void)
    146138    { if (!instance_) instance_=new SVN; return instance_; }
     
    172164    /// SVN::instance.
    173165    ///
    174     /// @todo Make sure that proper cleanup is performed before
    175     /// throwing an exception.
    176     ///
    177166    SVN(void);
    178167
     
    181170    ///
    182171    SVN(const SVN&);
     172
     173    ///
     174    /// Free resources when failing to reach end of constructor.
     175    ///
     176    void cleanup_failed_initialization(svn_error_t *err);
    183177
    184178    static SVN* instance_;
  • trunk/lib/SVNinfo.cc

    r138 r140  
    4646      throw SVNException(std::string("SVNinfo::info_receriver: ") +
    4747                         "Failed to acquire an svn info object");
    48     static_cast<struct info_receiver_baton_*>(baton)->info=svn_info_dup(info,
    49                                                                         pool);
    50     return SVN_NO_ERROR;
     48    static_cast<struct info_receiver_baton*>(baton)->info=svn_info_dup(info,
     49                                                                       pool);
     50    return SVN_NO_ERROR;
    5151  }
    5252
  • trunk/lib/SVNinfo.h

    r129 r140  
    9090    /// @see info_receiver
    9191    ///
    92     struct info_receiver_baton_ {
     92    struct info_receiver_baton {
    9393      svn_info_t *info;
    9494    } info_receiver_baton_ ;
Note: See TracChangeset for help on using the changeset viewer.