I noticed a coverity scan defect in RageUtil_AutoPtr and when I looked at the file it looked like mostly a homegrown shared_ptr and unique_ptr, so this patch removes them and replaces them with those 2. When removing the file from cmake, I also found a TODO comment indicating they should be replaced with std smart pointers: "Utils/RageUtil_AutoPtr.h" # TODO: Remove the need for this and replace with c++11 smart pointers
There were 2 big differences these had with the std smart pointers:
AutoPtrCopyOnWrite had a Get method that, if the count was not 1, made a new allocation/copy for copy-on-write semantics. This has only used in 3 places, and I replaced it with if (ptr.use_count() != 1) ptr = std::make_shared(*ptr);
HiddenPtr implemented a copy constructor HiddenPtr(const HiddenPtr<T>& cpy) which unique_ptr does not implement (It only has a move constructor and a nullptr constructor). I was mostly able to work around this, except in HighScore and NoteData where I made wrappers (HSImplUniquePtr and UniquePtrNoteData). HighScore uses that pointer to implement the C++ "pimpl idiom", and I thought using a wrapper like that was less error-prone since if a new field is added it is automatically copied in the default compiler-generated copy constructor, whereas if we implement it manually it would have to manually be added.
I think I also fixed a memory leak in MusicWheel: It doesn't look like the elements of std::vector<MusicWheelItemData*> m__UnFilteredWheelItemDatas[NUM_SortOrder]; were ever being freed, and they were created by BuildWheelItemDatas via operator new.
I noticed a coverity scan defect in
RageUtil_AutoPtr
and when I looked at the file it looked like mostly a homegrown shared_ptr and unique_ptr, so this patch removes them and replaces them with those 2. When removing the file from cmake, I also found a TODO comment indicating they should be replaced with std smart pointers:"Utils/RageUtil_AutoPtr.h" # TODO: Remove the need for this and replace with c++11 smart pointers
There were 2 big differences these had with the std smart pointers:
if (ptr.use_count() != 1) ptr = std::make_shared(*ptr);
HiddenPtr(const HiddenPtr<T>& cpy)
which unique_ptr does not implement (It only has a move constructor and a nullptr constructor). I was mostly able to work around this, except in HighScore and NoteData where I made wrappers (HSImplUniquePtr
andUniquePtrNoteData
). HighScore uses that pointer to implement the C++ "pimpl idiom", and I thought using a wrapper like that was less error-prone since if a new field is added it is automatically copied in the default compiler-generated copy constructor, whereas if we implement it manually it would have to manually be added.I think I also fixed a memory leak in MusicWheel: It doesn't look like the elements of
std::vector<MusicWheelItemData*> m__UnFilteredWheelItemDatas[NUM_SortOrder];
were ever being freed, and they were created byBuildWheelItemDatas
via operator new.