aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2020-12-20 22:29:25 +0100
committerJan200101 <sentrycraft123@gmail.com>2020-12-20 22:31:57 +0100
commit8cb74a7817bc5769a28a12cabb90276947f8051a (patch)
tree24ecd4939c4dac787c3426ab40308456476c80e9 /src
parent88b8a63729c6c322c8bb456fd0f921846f48d751 (diff)
downloadpolecat-8cb74a7817bc5769a28a12cabb90276947f8051a.tar.gz
polecat-8cb74a7817bc5769a28a12cabb90276947f8051a.zip
add some memory allocation failure checks
Diffstat (limited to 'src')
-rw-r--r--src/net.c7
-rw-r--r--src/wine.c31
2 files changed, 25 insertions, 13 deletions
diff --git a/src/net.c b/src/net.c
index c20f076..a90533b 100644
--- a/src/net.c
+++ b/src/net.c
@@ -18,7 +18,7 @@ static size_t memoryCallback(void* contents, size_t size, size_t nmemb, void* us
uint8_t* ptr = realloc(mem->memory, mem->size + realsize + 1);
if(ptr == NULL)
{
- puts("out of memory");
+ fprintf(stderr, "Unable to allocate memory\n");
return 0;
}
@@ -55,6 +55,7 @@ struct MemoryStruct* downloadToRam(const char* URL, long noprogress)
if (chunk)
{
+ // if we managed to allocate the chunk lets assume we can allocate at least 1 byte
chunk->memory = malloc(1);
chunk->size = 0;
@@ -90,6 +91,10 @@ struct MemoryStruct* downloadToRam(const char* URL, long noprogress)
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
}
+ else
+ {
+ fprintf(stderr, "Unable to allocate memory\n");
+ }
return chunk;
}
diff --git a/src/wine.c b/src/wine.c
index 46bfd46..c8680d0 100644
--- a/src/wine.c
+++ b/src/wine.c
@@ -385,22 +385,29 @@ enum wine_type_t check_wine_ver(char* winepath, size_t size)
char* winepathcopy = NULL;
winepathcopy = malloc(size);
- strncpy(winepathcopy, winepath, size);
- strncat(winepathcopy, WINEBIN, size - strlen(winepathcopy));
-
- if (isFile(winepathcopy))
+ if (winepathcopy)
{
- free(winepathcopy);
- return WINE_NORMAL;
- }
+ strncpy(winepathcopy, winepath, size);
+ strncat(winepathcopy, WINEBIN, size - strlen(winepathcopy));
+
+ if (isFile(winepathcopy))
+ {
+ free(winepathcopy);
+ return WINE_NORMAL;
+ }
- strncpy(winepathcopy, winepath, size);
- strncat(winepathcopy, PROTONBIN, size - strlen(winepathcopy));
+ strncpy(winepathcopy, winepath, size);
+ strncat(winepathcopy, PROTONBIN, size - strlen(winepathcopy));
- if (isFile(winepathcopy))
+ if (isFile(winepathcopy))
+ {
+ free(winepathcopy);
+ return WINE_PROTON;
+ }
+ }
+ else
{
- free(winepathcopy);
- return WINE_PROTON;
+ fprintf(stderr, "Unable to allocate memory\n");
}
return WINE_NONE;