Fix a few small memleaks

This commit is contained in:
Iwan Timmer 2015-08-14 15:23:40 +02:00
parent 01466c9bb9
commit dee2231bf2
4 changed files with 29 additions and 10 deletions

View File

@ -350,7 +350,6 @@ int gs_pair(PSERVER_DATA server, char* pin) {
if ((ret = http_request(url, data)) != GS_OK)
goto cleanup;
printf("Paired\n");
server->paired = true;
cleanup:

View File

@ -23,6 +23,8 @@
#include <expat.h>
#include <string.h>
static XML_Parser parser;
struct xml_query {
char *memory;
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)) {
int code = XML_GetErrorCode(parser);
gs_error = XML_ErrorString(code);
XML_ParserFree(parser);
free(search.memory);
return GS_INVALID;
} else if (search.memory == NULL)
} else if (search.memory == NULL) {
XML_ParserFree(parser);
return GS_OUT_OF_MEMORY;
}
XML_ParserFree(parser);
*result = search.memory;
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)) {
int code = XML_GetErrorCode(parser);
gs_error = XML_ErrorString(code);
XML_ParserFree(parser);
return GS_INVALID;
}
XML_ParserFree(parser);
*app_list = (PAPP_LIST) query.data;
return GS_OK;

View File

@ -83,22 +83,26 @@ char* get_path(char* name, char* extra_data_dirs) {
exit(-1);
}
char* data_dir = data_dirs;
char* end;
do {
end = strstr(data_dirs, ":");
int length = end != NULL?end - data_dirs:strlen(data_dirs);
memcpy(path, data_dirs, length);
end = strstr(data_dir, ":");
int length = end != NULL?end - data_dir:strlen(data_dir);
memcpy(path, data_dir, length);
if (path[0] == '/')
sprintf(path+length, MOONLIGHT_PATH "/%s", name);
else
sprintf(path+length, "/%s", name);
if(access(path, R_OK) != -1)
if(access(path, R_OK) != -1) {
free(data_dirs);
return path;
}
data_dirs = end + 1;
data_dir = end + 1;
} while (end != NULL);
free(data_dirs);
free(path);
return NULL;
}

View File

@ -190,7 +190,14 @@ int main(int argc, char* argv[]) {
SERVER_DATA server;
server.address = config.address;
if (gs_init(&server, config.key_dir) != GS_OK) {
int ret;
if ((ret = gs_init(&server, config.key_dir)) == GS_OUT_OF_MEMORY) {
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);
}