Skip to content

Commit e51f7c3

Browse files
committed
Remove a potential race condition
1 parent 5244538 commit e51f7c3

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Core/Reporting.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ namespace Reporting
6868

6969
// Internal limiter on number of requests per instance.
7070
static u32 spamProtectionCount = 0;
71-
// Temporarily stores a reference to the hostname.
72-
static std::string lastHostname;
73-
7471
// Keeps track of whether a harmful setting was ever used.
7572
static bool everUnsupported = false;
7673
// Support is cached here to avoid checking it on every single request.
@@ -231,7 +228,7 @@ namespace Reporting
231228
// Returns the full host (e.g. report.ppsspp.org:80.)
232229
std::string ServerHost() {
233230
if (g_Config.sReportHost.compare("default") == 0)
234-
return "";
231+
return "report.ppsspp.org";
235232
return g_Config.sReportHost;
236233
}
237234

@@ -255,8 +252,7 @@ namespace Reporting
255252
}
256253

257254
// Returns only the hostname part (e.g. "report.ppsspp.org".)
258-
static const char *ServerHostname()
259-
{
255+
static std::string ServerHostname() {
260256
if (!IsEnabled())
261257
return NULL;
262258

@@ -265,10 +261,9 @@ namespace Reporting
265261

266262
// This means there's no port number - it's already the hostname.
267263
if (length == host.npos)
268-
lastHostname = host;
264+
return host;
269265
else
270-
lastHostname = host.substr(0, length);
271-
return lastHostname.c_str();
266+
return host.substr(0, length);
272267
}
273268

274269
// Returns only the port part (e.g. 80) as an int.
@@ -296,9 +291,9 @@ namespace Reporting
296291

297292
static void SendReportRequest(const char *uri, const std::string &data, const std::string &mimeType, std::function<void(http::Request &)> callback) {
298293
char url[1024];
299-
const char *hostname = ServerHostname();
294+
std::string hostname = ServerHostname();
300295
int port = ServerPort();
301-
snprintf(url, sizeof(url), "http://%s:%d%s", hostname, port, uri);
296+
snprintf(url, sizeof(url), "http://%s:%d%s", hostname.c_str(), port, uri);
302297
g_DownloadManager.AsyncPostWithCallback(url, data, mimeType, http::ProgressBarMode::NONE, callback);
303298
}
304299

0 commit comments

Comments
 (0)