diff options
| author | jacob1 <jfu614@gmail.com> | 2012-08-08 16:28:34 (GMT) |
|---|---|---|
| committer | jacksonmj <mj-pt@jacksonmj.co.uk> | 2012-08-13 23:05:48 (GMT) |
| commit | 3c78cce7a56c91b7c4db8526f988101a5e1e2b2c (patch) | |
| tree | 2d47dfcd85b085e62326ad9df8b31b320e979442 /src/save.c | |
| parent | 8ec0f41fb143a6bda08d078232f3d70b36328dc4 (diff) | |
| download | powder-3c78cce7a56c91b7c4db8526f988101a5e1e2b2c.zip powder-3c78cce7a56c91b7c4db8526f988101a5e1e2b2c.tar.gz | |
fix many crashes when out of memory
Diffstat (limited to 'src/save.c')
| -rw-r--r-- | src/save.c | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -494,6 +494,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h wallDataLen = blockW*blockH; fanData = malloc((blockW*blockH)*2); fanDataLen = 0; + if (!wallData || !fanData) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } for(x = blockX; x < blockX+blockW; x++) { for(y = blockY; y < blockY+blockH; y++) @@ -534,6 +540,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h partsPosLastMap = calloc(fullW*fullH, sizeof(unsigned)); partsPosCount = calloc(fullW*fullH, sizeof(unsigned)); partsPosLink = calloc(NPART, sizeof(unsigned)); + if (!partsPosFirstMap || !partsPosLastMap || !partsPosCount || !partsPosLink) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } for(i = 0; i < NPART; i++) { if(partsptr[i].type) @@ -565,6 +577,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h //Store number of particles in each position partsPosData = malloc(fullW*fullH*3); partsPosDataLen = 0; + if (!partsPosData) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } for (y=0;y<fullH;y++) { for (x=0;x<fullW;x++) @@ -586,6 +604,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h partsDataLen = 0; partsSaveIndex = calloc(NPART, sizeof(unsigned)); partsCount = 0; + if (!partsData || !partsSaveIndex) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } for (y=0;y<fullH;y++) { for (x=0;x<fullW;x++) @@ -726,6 +750,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h soapLinkData = malloc(3*elementCount[PT_SOAP]); soapLinkDataLen = 0; + if (!soapLinkData) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } //Iterate through particles in the same order that they were saved for (y=0;y<fullH;y++) { @@ -822,7 +852,13 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h finalData = bson_data(&b); finalDataLen = bson_size(&b); outputDataLen = finalDataLen*2+12; - outputData = malloc(outputDataLen); + outputData = (unsigned char*)malloc(outputDataLen); + if (!outputData) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } outputData[0] = 'O'; outputData[1] = 'P'; |
