mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-06-17 06:11:03 +00:00
Fix unsafe modification of the peer variable during shutdown
This commit is contained in:
+7
-1
@@ -291,6 +291,12 @@ static int sendMessageEnet(short ptype, short paylen, const void* payload) {
|
|||||||
int err;
|
int err;
|
||||||
|
|
||||||
LC_ASSERT(ServerMajorVersion >= 5);
|
LC_ASSERT(ServerMajorVersion >= 5);
|
||||||
|
|
||||||
|
// We may be trying to disconnect, so our peer could be gone.
|
||||||
|
// This check is safe because we're guaranteed to be holding enetMutex.
|
||||||
|
if (peer == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
packet = malloc(sizeof(*packet) + paylen);
|
packet = malloc(sizeof(*packet) + paylen);
|
||||||
if (packet == NULL) {
|
if (packet == NULL) {
|
||||||
@@ -570,6 +576,7 @@ int stopControlStream(void) {
|
|||||||
if (peer != NULL) {
|
if (peer != NULL) {
|
||||||
PltLockMutex(&enetMutex);
|
PltLockMutex(&enetMutex);
|
||||||
enet_peer_disconnect_now(peer, 0);
|
enet_peer_disconnect_now(peer, 0);
|
||||||
|
peer = NULL;
|
||||||
PltUnlockMutex(&enetMutex);
|
PltUnlockMutex(&enetMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -586,7 +593,6 @@ int stopControlStream(void) {
|
|||||||
PltCloseThread(&lossStatsThread);
|
PltCloseThread(&lossStatsThread);
|
||||||
PltCloseThread(&invalidateRefFramesThread);
|
PltCloseThread(&invalidateRefFramesThread);
|
||||||
|
|
||||||
peer = NULL;
|
|
||||||
if (client != NULL) {
|
if (client != NULL) {
|
||||||
enet_host_destroy(client);
|
enet_host_destroy(client);
|
||||||
client = NULL;
|
client = NULL;
|
||||||
|
|||||||
Reference in New Issue
Block a user