Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f74cc06

Browse files
Deepak Majetiomalley
authored andcommitted
ORC-122. Use unique_ptr to wrap Timezone instances in the cache.
Fixes apache#73 Signed-off-by: Owen O'Malley <[email protected]>
1 parent 31267f1 commit f74cc06

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

c++/src/Timezone.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ namespace orc {
651651
DIAGNOSTIC_IGNORE("-Wexit-time-destructors")
652652
#endif
653653
static std::mutex timezone_mutex;
654-
static std::map<std::string, Timezone*> timezoneCache;
654+
static std::map<std::string, std::unique_ptr<Timezone> > timezoneCache;
655655
DIAGNOSTIC_POP
656656

657657
Timezone::~Timezone() {
@@ -691,10 +691,10 @@ namespace orc {
691691
const Timezone& getTimezoneByFilename(const std::string& filename) {
692692
// ORC-110
693693
std::lock_guard<std::mutex> timezone_lock(timezone_mutex);
694-
std::map<std::string, Timezone*>::iterator itr =
694+
std::map<std::string, std::unique_ptr<Timezone> >::iterator itr =
695695
timezoneCache.find(filename);
696696
if (itr != timezoneCache.end()) {
697-
return *(itr->second);
697+
return *(itr->second).get();
698698
}
699699
int in = open(filename.c_str(), O_RDONLY);
700700
if (in == -1) {
@@ -729,9 +729,8 @@ namespace orc {
729729
err << "failed to close " << filename << " - " << strerror(errno);
730730
throw TimezoneError(err.str());
731731
}
732-
Timezone* result = new TimezoneImpl(filename, buffer);
733-
timezoneCache[filename] = result;
734-
return *result;
732+
timezoneCache[filename].reset(new TimezoneImpl(filename, buffer));
733+
return *timezoneCache[filename].get();
735734
}
736735

737736
/**

0 commit comments

Comments
 (0)