Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion stl/src/tzdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,31 @@ void __stdcall __std_tzdb_delete_current_zone(__std_tzdb_current_zone_info* cons

_Info->_Abbrev = _Allocate_wide_to_narrow(_Abbrev.get(), _Abbrev_len, _Info->_Err);
if (_Info->_Abbrev == nullptr) {
return _Propagate_error(_Info);
const auto _Abs_offset = _Info->_Offset < 0 ? -_Info->_Offset : _Info->_Offset;
const auto _Offset_in_minutes = _Abs_offset / (60 * 1000);
const auto _Hours = _Offset_in_minutes / 60;
const auto _Mins = _Offset_in_minutes % 60;

_STD unique_ptr<char[]> _Fallback_abbrev{new (_STD nothrow) char[_Mins == 0 ? 4 : 6]};

if (_Fallback_abbrev == nullptr) {
return nullptr;
}

_Fallback_abbrev[0] = _Info->_Offset < 0 ? '-' : '+';
_Fallback_abbrev[1] = static_cast<char>('0' + _Hours / 10);
_Fallback_abbrev[2] = static_cast<char>('0' + _Hours % 10);

if (_Mins == 0) {
_Fallback_abbrev[3] = '\0';
} else {
_Fallback_abbrev[3] = static_cast<char>('0' + _Mins / 10);
_Fallback_abbrev[4] = static_cast<char>('0' + _Mins % 10);
_Fallback_abbrev[5] = '\0';
}

_Info->_Err = __std_tzdb_error::_Success;
_Info->_Abbrev = _Fallback_abbrev.release();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for commenting after a merge, but does this release() call means we are leaking memory?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't leaking memory. The returned __std_tzdb_sys_info* will be stored in a unique_ptr<__std_tzdb_sys_info, _Tzdb_deleter<__std_tzdb_sys_info>>, which will call __std_tzdb_delete_sys_info in its destructor, which will perform delete[] _Info->_Abbrev;

}

return _Info.release();
Expand Down