mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 09:25:49 +00:00
Fix memory leaks in the control stream code
This commit is contained in:
parent
330cb36490
commit
378e05fccf
@ -120,16 +120,25 @@ static int sendMessageAndForget(short ptype, short paylen, const void* payload)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PNVCTL_PACKET_HEADER sendMessage(short ptype, short paylen, const void* payload) {
|
static PNVCTL_PACKET_HEADER sendMessage(short ptype, short paylen, const void* payload) {
|
||||||
int success;
|
if (!sendMessageAndForget(ptype, paylen, payload)) {
|
||||||
|
return NULL;
|
||||||
success = sendMessageAndForget(ptype, paylen, payload);
|
}
|
||||||
if (!success) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return readNvctlPacket();
|
return readNvctlPacket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int sendMessageAndDiscardReply(short ptype, short paylen, const void* payload) {
|
||||||
|
PNVCTL_PACKET_HEADER reply;
|
||||||
|
|
||||||
|
reply = sendMessage(ptype, paylen, payload);
|
||||||
|
if (reply == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(reply);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
static void lossStatsThreadFunc(void* context) {
|
static void lossStatsThreadFunc(void* context) {
|
||||||
char lossStatsPayload[PPAYLEN_LOSS_STATS];
|
char lossStatsPayload[PPAYLEN_LOSS_STATS];
|
||||||
BYTE_BUFFER byteBuffer;
|
BYTE_BUFFER byteBuffer;
|
||||||
@ -162,7 +171,6 @@ static void lossStatsThreadFunc(void* context) {
|
|||||||
|
|
||||||
static void resyncThreadFunc(void* context) {
|
static void resyncThreadFunc(void* context) {
|
||||||
long long payload[3];
|
long long payload[3];
|
||||||
PNVCTL_PACKET_HEADER response;
|
|
||||||
|
|
||||||
while (!PltIsThreadInterrupted(&resyncThread)) {
|
while (!PltIsThreadInterrupted(&resyncThread)) {
|
||||||
// Wait for a resync request
|
// Wait for a resync request
|
||||||
@ -177,8 +185,7 @@ static void resyncThreadFunc(void* context) {
|
|||||||
PltClearEvent(&resyncEvent);
|
PltClearEvent(&resyncEvent);
|
||||||
|
|
||||||
// Send the resync request and read the response
|
// Send the resync request and read the response
|
||||||
response = sendMessage(PTYPE_RESYNC, PPAYLEN_RESYNC, payload);
|
if (!sendMessageAndDiscardReply(PTYPE_RESYNC, PPAYLEN_RESYNC, payload)) {
|
||||||
if (response == NULL) {
|
|
||||||
Limelog("Resync thread terminating #1\n");
|
Limelog("Resync thread terminating #1\n");
|
||||||
listenerCallbacks->connectionTerminated(LastSocketError());
|
listenerCallbacks->connectionTerminated(LastSocketError());
|
||||||
return;
|
return;
|
||||||
@ -207,7 +214,6 @@ int stopControlStream(void) {
|
|||||||
|
|
||||||
int startControlStream(void) {
|
int startControlStream(void) {
|
||||||
int err;
|
int err;
|
||||||
PNVCTL_PACKET_HEADER response;
|
|
||||||
|
|
||||||
ctlSock = connectTcpSocket(host, 47995);
|
ctlSock = connectTcpSocket(host, 47995);
|
||||||
if (ctlSock == INVALID_SOCKET) {
|
if (ctlSock == INVALID_SOCKET) {
|
||||||
@ -217,18 +223,18 @@ int startControlStream(void) {
|
|||||||
enableNoDelay(ctlSock);
|
enableNoDelay(ctlSock);
|
||||||
|
|
||||||
// Send START A
|
// Send START A
|
||||||
response = sendMessage(PTYPE_START_STREAM_A,
|
if (!sendMessageAndDiscardReply(PTYPE_START_STREAM_A,
|
||||||
PPAYLEN_START_STREAM_A, PPAYLOAD_START_STREAM_A);
|
PPAYLEN_START_STREAM_A,
|
||||||
if (response == NULL) {
|
PPAYLOAD_START_STREAM_A)) {
|
||||||
return LastSocketError();
|
return LastSocketError();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send START B
|
// Send START B
|
||||||
response = sendMessage(PTYPE_START_STREAM_B,
|
if (!sendMessageAndDiscardReply(PTYPE_START_STREAM_B,
|
||||||
PPAYLEN_START_STREAM_B, PPAYLOAD_START_STREAM_B);
|
PPAYLEN_START_STREAM_B,
|
||||||
if (response == NULL) {
|
PPAYLOAD_START_STREAM_B)) {
|
||||||
return LastSocketError();
|
return LastSocketError();
|
||||||
}
|
}
|
||||||
|
|
||||||
err = PltCreateThread(lossStatsThreadFunc, NULL, &lossStatsThread);
|
err = PltCreateThread(lossStatsThreadFunc, NULL, &lossStatsThread);
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user