mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2025-07-01 23:35:47 +00:00
Fix a few small memleaks
This commit is contained in:
parent
01466c9bb9
commit
dee2231bf2
@ -350,7 +350,6 @@ int gs_pair(PSERVER_DATA server, char* pin) {
|
|||||||
if ((ret = http_request(url, data)) != GS_OK)
|
if ((ret = http_request(url, data)) != GS_OK)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
printf("Paired\n");
|
|
||||||
server->paired = true;
|
server->paired = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -23,6 +23,8 @@
|
|||||||
#include <expat.h>
|
#include <expat.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
static XML_Parser parser;
|
||||||
|
|
||||||
struct xml_query {
|
struct xml_query {
|
||||||
char *memory;
|
char *memory;
|
||||||
size_t size;
|
size_t size;
|
||||||
@ -103,11 +105,15 @@ int xml_search(char* data, size_t len, char* node, char** result) {
|
|||||||
if (! XML_Parse(parser, data, len, 1)) {
|
if (! XML_Parse(parser, data, len, 1)) {
|
||||||
int code = XML_GetErrorCode(parser);
|
int code = XML_GetErrorCode(parser);
|
||||||
gs_error = XML_ErrorString(code);
|
gs_error = XML_ErrorString(code);
|
||||||
|
XML_ParserFree(parser);
|
||||||
free(search.memory);
|
free(search.memory);
|
||||||
return GS_INVALID;
|
return GS_INVALID;
|
||||||
} else if (search.memory == NULL)
|
} else if (search.memory == NULL) {
|
||||||
|
XML_ParserFree(parser);
|
||||||
return GS_OUT_OF_MEMORY;
|
return GS_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
XML_ParserFree(parser);
|
||||||
*result = search.memory;
|
*result = search.memory;
|
||||||
|
|
||||||
return GS_OK;
|
return GS_OK;
|
||||||
@ -126,8 +132,11 @@ int xml_applist(char* data, size_t len, PAPP_LIST *app_list) {
|
|||||||
if (! XML_Parse(parser, data, len, 1)) {
|
if (! XML_Parse(parser, data, len, 1)) {
|
||||||
int code = XML_GetErrorCode(parser);
|
int code = XML_GetErrorCode(parser);
|
||||||
gs_error = XML_ErrorString(code);
|
gs_error = XML_ErrorString(code);
|
||||||
|
XML_ParserFree(parser);
|
||||||
return GS_INVALID;
|
return GS_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XML_ParserFree(parser);
|
||||||
*app_list = (PAPP_LIST) query.data;
|
*app_list = (PAPP_LIST) query.data;
|
||||||
|
|
||||||
return GS_OK;
|
return GS_OK;
|
||||||
|
14
src/config.c
14
src/config.c
@ -83,22 +83,26 @@ char* get_path(char* name, char* extra_data_dirs) {
|
|||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* data_dir = data_dirs;
|
||||||
char* end;
|
char* end;
|
||||||
do {
|
do {
|
||||||
end = strstr(data_dirs, ":");
|
end = strstr(data_dir, ":");
|
||||||
int length = end != NULL?end - data_dirs:strlen(data_dirs);
|
int length = end != NULL?end - data_dir:strlen(data_dir);
|
||||||
memcpy(path, data_dirs, length);
|
memcpy(path, data_dir, length);
|
||||||
if (path[0] == '/')
|
if (path[0] == '/')
|
||||||
sprintf(path+length, MOONLIGHT_PATH "/%s", name);
|
sprintf(path+length, MOONLIGHT_PATH "/%s", name);
|
||||||
else
|
else
|
||||||
sprintf(path+length, "/%s", name);
|
sprintf(path+length, "/%s", name);
|
||||||
|
|
||||||
if(access(path, R_OK) != -1)
|
if(access(path, R_OK) != -1) {
|
||||||
|
free(data_dirs);
|
||||||
return path;
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
data_dirs = end + 1;
|
data_dir = end + 1;
|
||||||
} while (end != NULL);
|
} while (end != NULL);
|
||||||
|
|
||||||
|
free(data_dirs);
|
||||||
free(path);
|
free(path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
13
src/main.c
13
src/main.c
@ -190,9 +190,16 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
SERVER_DATA server;
|
SERVER_DATA server;
|
||||||
server.address = config.address;
|
server.address = config.address;
|
||||||
if (gs_init(&server, config.key_dir) != GS_OK) {
|
int ret;
|
||||||
fprintf(stderr, "Can't connect to server %s\n", config.address);
|
if ((ret = gs_init(&server, config.key_dir)) == GS_OUT_OF_MEMORY) {
|
||||||
exit(-1);
|
fprintf(stderr, "Not enough memory\n");
|
||||||
|
exit(-1);
|
||||||
|
} else if (ret == GS_INVALID) {
|
||||||
|
fprintf(stderr, "Invalid data received from server: %s\n", config.address, gs_error);
|
||||||
|
exit(-1);
|
||||||
|
} else if (ret != GS_OK) {
|
||||||
|
fprintf(stderr, "Can't connect to server %s\n", config.address);
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp("list", config.action) == 0) {
|
if (strcmp("list", config.action) == 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user