Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core/HLE/Dialog] Fixed memleak after first return error and increase lifetime in current scope #19006

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 5 additions & 6 deletions Core/Dialog/SavedataParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,15 +513,15 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD
// For each file, 13 bytes for filename, 16 bytes for file hash (0 in PPSSPP), 3 byte for padding
u32 tmpDataSize = 0;
SaveSFOFileListEntry *tmpDataOrig = (SaveSFOFileListEntry *)sfoFile->GetValueData("SAVEDATA_FILE_LIST", &tmpDataSize);
SaveSFOFileListEntry *updatedList = new SaveSFOFileListEntry[FILE_LIST_COUNT_MAX];
auto updatedList = std::make_unique<SaveSFOFileListEntry[]>(FILE_LIST_COUNT_MAX);
if (tmpDataSize != 0)
memcpy(updatedList, tmpDataOrig, std::min(tmpDataSize, FILE_LIST_TOTAL_SIZE));
memcpy(updatedList.get(), tmpDataOrig, std::min(tmpDataSize, FILE_LIST_TOTAL_SIZE));
if (tmpDataSize < FILE_LIST_TOTAL_SIZE)
memset(updatedList + tmpDataSize, 0, FILE_LIST_TOTAL_SIZE - tmpDataSize);
memset(updatedList.get() + tmpDataSize, 0, FILE_LIST_TOTAL_SIZE - tmpDataSize);
// Leave a hash there and unchanged if it was already there.
if (secureMode && param->dataBuf.IsValid()) {
const std::string saveFilename = GetFileName(param);
for (auto entry = updatedList; entry < updatedList + FILE_LIST_COUNT_MAX; ++entry) {
for (auto entry = updatedList.get(); entry < updatedList.get() + FILE_LIST_COUNT_MAX; ++entry) {
if (entry->filename[0] != '\0') {
if (strncmp(entry->filename, saveFilename.c_str(), sizeof(entry->filename)) != 0)
continue;
Expand All @@ -533,8 +533,7 @@ int SavedataParam::Save(SceUtilitySavedataParam* param, const std::string &saveD
}
}

sfoFile->SetValue("SAVEDATA_FILE_LIST", (u8 *)updatedList, FILE_LIST_TOTAL_SIZE, (int)FILE_LIST_TOTAL_SIZE);
delete[] updatedList;
sfoFile->SetValue("SAVEDATA_FILE_LIST", (u8 *)updatedList.get(), FILE_LIST_TOTAL_SIZE, (int)FILE_LIST_TOTAL_SIZE);

// Init param with 0. This will be used to detect crypted save or not on loading
u8 *tmpData = new u8[128];
Expand Down
10 changes: 4 additions & 6 deletions Core/HLE/sceFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1084,13 +1084,12 @@ static u32 sceFontOpenUserMemory(u32 libHandle, u32 memoryFontPtr, u32 memoryFon
while (!Memory::IsValidAddress(memoryFontPtr + memoryFontLength - 1)) {
--memoryFontLength;
}
Font *f = new Font(fontData, memoryFontLength);
LoadedFont *font = fontLib->OpenFont(f, FONT_OPEN_USERBUFFER, *errorCode);
auto f = std::make_unique<Font>(fontData, memoryFontLength);
LoadedFont *font = fontLib->OpenFont(f.get(), FONT_OPEN_USERBUFFER, *errorCode);
if (font) {
*errorCode = 0;
return hleLogSuccessX(SCEFONT, font->Handle());
}
delete f;
return 0;
}

Expand Down Expand Up @@ -1123,15 +1122,14 @@ static u32 sceFontOpenUserFile(u32 libHandle, const char *fileName, u32 mode, u3
return hleLogError(SCEFONT, 0, "file does not exist");
}

Font *f = new Font(buffer);
auto f = std::make_unique<Font>(buffer);
FontOpenMode openMode = mode == 0 ? FONT_OPEN_USERFILE_HANDLERS : FONT_OPEN_USERFILE_FULL;
LoadedFont *font = fontLib->OpenFont(f, openMode, *errorCode);
LoadedFont *font = fontLib->OpenFont(f.get(), openMode, *errorCode);
if (font) {
*errorCode = 0;
return hleLogSuccessInfoX(SCEFONT, font->Handle());
}

delete f;
// Message was already logged.
return 0;
}
Expand Down
3 changes: 1 addition & 2 deletions Core/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ static void ExecuteWebServer() {

AndroidJNIThreadContext context; // Destructor detaches.

auto http = new http::Server(new NewThreadExecutor());
auto http = std::make_unique<http::Server>(new NewThreadExecutor());
http->RegisterHandler("/", &HandleListing);
// This lists all the (current) recent ISOs.
http->SetFallbackHandler(&HandleFallback);
Expand Down Expand Up @@ -437,7 +437,6 @@ static void ExecuteWebServer() {

http->Stop();
StopAllDebuggers();
delete http;

UpdateStatus(ServerStatus::FINISHED);
}
Expand Down