[commit] r1260 - trunk/GME/Common
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Mon Apr 11 09:53:52 CDT 2011
Author: ksmyth
Date: Mon Apr 11 09:53:51 2011
New Revision: 1260
Log:
Use RAII to avoid leaks when the loop is exited (return or exception)
Modified:
trunk/GME/Common/CommonMgaTrukk.h
Modified: trunk/GME/Common/CommonMgaTrukk.h
==============================================================================
--- trunk/GME/Common/CommonMgaTrukk.h Fri Apr 8 10:34:08 2011 (r1259)
+++ trunk/GME/Common/CommonMgaTrukk.h Mon Apr 11 09:53:51 2011 (r1260)
@@ -2,6 +2,8 @@
#ifndef MGA_COMMONMGATRUKK_H
#define MGA_COMMONMGATRUKK_H
+#include <memory>
+
template < class t >
class SmartMultiPtr {
CComPtr< t > *m_ptr;
@@ -18,19 +20,18 @@
long iter_count = 0; \
COMTHROW( collifptr->get_Count(&iter_count) ); \
ASSERT( iter_count >= 0 ); \
- CComPtr<iftype> *arrptr, *arrend, *array = new CComPtr<iftype>[iter_count]; \
+ std::unique_ptr<CComPtr<iftype>[]> array(new CComPtr<iftype>[iter_count]); \
+ CComPtr<iftype> *arrptr, *arrend; \
if(iter_count > 0) \
- COMTHROW( collifptr->GetAll(iter_count, &(*array)) ); \
- arrend = array+iter_count; \
- for(arrptr = array; arrptr != arrend; arrptr++)
+ COMTHROW( collifptr->GetAll(iter_count, &(*array.get())) ); \
+ arrend = array.get()+iter_count; \
+ for(arrptr = array.get(); arrptr != arrend; arrptr++)
#define MGACOLL_ITER (*arrptr)
#define MGACOLL_AT_END (arrptr == arrend)
-#define MGACOLL_ITERATE_END \
- delete[] array; \
-}
+#define MGACOLL_ITERATE_END }
#endif//MGA_COMMONMGATRUKK_H
More information about the gme-commit
mailing list