From: <jim...@us...> - 2009-10-08 02:48:21
|
Revision: 1097 http://panotools.svn.sourceforge.net/panotools/?rev=1097&view=rev Author: jim0watters Date: 2009-10-08 02:48:06 +0000 (Thu, 08 Oct 2009) Log Message: ----------- ColourBrightness.c, file.c, hdrfile.c, main.c, parser.c, PTcommon.c, ptstitch.c, tiff.c pttiff.h : Fixed many possible memory leaks with libpano. PTblender.c, PTmasker.c, PTmender.h, PTroller.c: Fixed many possible memory leaks for the tools. Modified Paths: -------------- trunk/clens/src/main.c trunk/libpano/ColourBrightness.c trunk/libpano/PTcommon.c trunk/libpano/file.c trunk/libpano/hdrfile.c trunk/libpano/parser.c trunk/libpano/ptstitch.c trunk/libpano/pttiff.h trunk/libpano/tiff.c trunk/libpano/tools/PTblender.c trunk/libpano/tools/PTmasker.c trunk/libpano/tools/PTmender.h trunk/libpano/tools/PTroller.c Modified: trunk/clens/src/main.c =================================================================== --- trunk/clens/src/main.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/clens/src/main.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -470,7 +470,7 @@ printf("output filename %s\n", outputFileName.name); - if (CreatePanorama(inputFileName, 1, &outputFileName, &scriptFileName) != 0) { + if (panoCreatePanorama(inputFileName, 1, &outputFileName, &scriptFileName) != 0) { puts("\tError processing image\n"); goto lbl_Next_Image; } Modified: trunk/libpano/ColourBrightness.c =================================================================== --- trunk/libpano/ColourBrightness.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/ColourBrightness.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -44,7 +44,7 @@ #define round(x) (int)(x) #endif -FILE *debugFile; +FILE *debugFile = 0; #ifdef __TESTING__ @@ -89,6 +89,7 @@ for (j=0; j<6 ; j++) { if ((ptrDouble = calloc(size, sizeof(double))) == NULL) { + /// @TODO clean up memory leak return NULL; } @@ -578,6 +579,12 @@ numberHistograms = ((counterImages-1) * counterImages)/2; + if(debugFile) + { + fclose(debugFile); + debugFile = 0; + } + debugFile = fopen("Debug.txt", "w"); // debugFile = stderr; @@ -934,15 +941,15 @@ { - double *remappedSourceHistogram; - double *accumToCorrectHistogram; - double *accumSourceHistogram; - int *processedImages; + double *remappedSourceHistogram = 0; + double *accumToCorrectHistogram = 0; + double *accumSourceHistogram = 0; + int *processedImages = 0; int currentImageNumber; int channel; int numberIntersections; - histograms_struct *currentHistogram; + histograms_struct *currentHistogram = 0; int j; int **ptrHistogram; @@ -964,18 +971,26 @@ remappedSourceHistogram = malloc(0x100 * sizeof(double)); - if ( processedImages == 0 ) + if ( processedImages == 0 + || accumToCorrectHistogram == 0 + || accumSourceHistogram == 0 + || remappedSourceHistogram == 0 ) + { + if ( processedImages != 0 ) + free(processedImages); + + if ( remappedSourceHistogram != 0 ) + free(remappedSourceHistogram); + + if ( accumToCorrectHistogram != 0 ) + free(accumToCorrectHistogram); + + if ( accumSourceHistogram != 0 ) + free(accumSourceHistogram); + return 0; - - if ( accumToCorrectHistogram == 0 ) - return 0; - - if (accumSourceHistogram == 0 ) - return 0; - - if (remappedSourceHistogram == 0 ) - return 0; - + } + // Mark starting image as done processedImages[calla->indexReferenceImage] = 1; @@ -1184,7 +1199,7 @@ int currentRow; int otherImage; int currentImage; - TIFF **ptrTIFFs; + TIFF **ptrTIFFs = NULL; uint16 samplesPerPixel; uint16 bitsPerSample; uint32 imageLength; @@ -1226,7 +1241,10 @@ crop_info_array = (CropInfo *)calloc(numberImages, sizeof(CropInfo)); if ( ptrTIFFs == NULL || crop_info_array == NULL ) - return 0; + { + saveReturnValue = 0; + goto Exit; + } currentImage = 0; @@ -1235,13 +1253,15 @@ if (GetFullPath(&fullPathImages[currentImage],tempString) != 0) { PrintError("Could not get filename"); - return(0); + saveReturnValue = 0; + goto Exit; } if ((ptrTIFFs[currentImage] = TIFFOpen(tempString, "r")) == NULL) { sprintf(tempString2, "Could not open TIFF file [%s]", tempString); PrintError(tempString2); - return NULL; + saveReturnValue = 0; + goto Exit; } getCropInformationFromTiff(ptrTIFFs[currentImage], &(crop_info_array[currentImage])); @@ -1268,7 +1288,8 @@ if ( imagesDataBuffer == 0 ) { PrintError("Not enough memory"); - return NULL; + saveReturnValue = 0; + goto Exit; } currentHistogram = ptrHistograms; @@ -1294,11 +1315,15 @@ for (i = 0 ; i < 6 ; i++) { if ((currentHistogram->ptrBaseHistograms[i] = calloc(currentHistogram->numberDifferentValues, sizeof(int))) == NULL) - return 0; - + { + saveReturnValue = 0; + goto Exit; + } if ((currentHistogram->ptrOtherHistograms[i] = calloc(currentHistogram->numberDifferentValues,sizeof(int))) == NULL) - return 0; - + { + saveReturnValue = 0; + goto Exit; + } } // for } //for (otherImage = currentImage + 1; otherImage < numberImages ; otherImage++, currentHistogram++) @@ -1323,7 +1348,8 @@ TIFFClose(ptrTIFFs[currentImage]); } //for - return 0; + saveReturnValue = 0; + goto Exit; } // progresss @@ -1482,6 +1508,7 @@ } +Exit: free(ptrTIFFs); free(imagesDataBuffer); Modified: trunk/libpano/PTcommon.c =================================================================== --- trunk/libpano/PTcommon.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/PTcommon.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -746,6 +746,7 @@ if ((regScript = LoadScript(scriptFileName)) == 0) { PrintError("Could not load ScriptFile"); + fclose(regFile); goto mainError; } @@ -757,6 +758,7 @@ // Make sure script was written completely if (regWritten != strlen(regScript)) { PrintError("Could not write temporary script"); + fclose(regFile); goto mainError; } @@ -1802,8 +1804,8 @@ pano_cropping_parms croppingParms; char outputPrefix[MAX_PATH_LENGTH]; int ptDeleteSources = 0; - fullPath *ptrInputFiles; - fullPath *ptrOutputFiles; + fullPath *ptrInputFiles = NULL; + fullPath *ptrOutputFiles = NULL; int base; int i; @@ -1857,6 +1859,8 @@ if ((ptrInputFiles = calloc(filesCount, sizeof(fullPath))) == NULL || (ptrOutputFiles = calloc(filesCount, sizeof(fullPath))) == NULL) { PrintError("Not enough memory"); + free(ptrInputFiles); + free(ptrOutputFiles); return -1; } Modified: trunk/libpano/file.c =================================================================== --- trunk/libpano/file.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/file.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -2005,6 +2005,7 @@ if( myopen( scriptFile, read_text, fnum )) { PrintError("Error Opening Scriptfile: %s", scriptFile->name); + free(script); goto _loadError; } Modified: trunk/libpano/hdrfile.c =================================================================== --- trunk/libpano/hdrfile.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/hdrfile.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -86,6 +86,7 @@ if ((outfile = fopen(filename, "wb")) == NULL) { PrintError("can't open %s", filename); + free( data ); return -1; } Modified: trunk/libpano/parser.c =================================================================== --- trunk/libpano/parser.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/parser.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -1470,6 +1470,7 @@ break; } } + panoLocaleRestore; } @@ -2131,7 +2132,7 @@ if( tP->r == NULL || tP->p == NULL ) { PrintError("Not enough memory"); - return -1; + goto fail; } Modified: trunk/libpano/ptstitch.c =================================================================== --- trunk/libpano/ptstitch.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/ptstitch.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -477,9 +477,9 @@ unsigned char *source; unsigned char *destination; - pano_Tiff *imageFile; - pano_Tiff *outputFile; - pano_Tiff *maskFile; + pano_Tiff *imageFile = NULL; + pano_Tiff *outputFile = NULL; + pano_Tiff *maskFile = NULL; int jumpBytes; int alphaChannelOffset; @@ -499,7 +499,8 @@ // Open input image if ((imageFile = panoTiffOpen(inputImage->name)) == NULL) { PrintError("Could not open TIFF-file"); - return 0; + returnValue = 0; + goto end; } //Allocate line buffers for image and mask @@ -507,20 +508,23 @@ || (maskRowBuffer = calloc(panoTiffBytesPerLine(imageFile), 1)) == NULL) { PrintError("Not enough memory"); - return 0; + returnValue = 0; + goto end; } // Open mask file if ((maskFile = panoTiffOpen(mask->name)) == NULL) { PrintError("Could not open mask file"); - return 0; + returnValue = 0; + goto end; } // Create output file if ((outputFile = panoTiffCreate(output->name, &maskFile->metadata)) == NULL) { PrintError("Could not create TIFF-file"); - return 0; + returnValue = 0; + goto end; } // Processing one row at a time @@ -571,15 +575,19 @@ returnValue = 1; end: - panoTiffClose(imageFile); - panoTiffClose(maskFile); - panoTiffClose(outputFile); + if(imageFile) + panoTiffClose(imageFile); + if(maskFile) + panoTiffClose(maskFile); + + if(outputFile) + panoTiffClose(outputFile); + free(imageRowBuffer); free(maskRowBuffer); return returnValue; - } @@ -803,8 +811,9 @@ int panoStitchReplaceMasks(fullPath * inputFiles, fullPath * outputFiles, int numberImages, int featherSize) { - fullPath *alphaChannelFiles; - fullPath *maskFiles; + int returnValue = -1; // default to fail + fullPath *alphaChannelFiles = NULL; + fullPath *maskFiles = NULL; int i; Image image; char tempString[512]; @@ -822,18 +831,18 @@ if (maskFiles == NULL || alphaChannelFiles == NULL) { PrintError("Not enough memory"); - return -1; + goto end; } // CREATE stitching maps if (!panoStitchCreateMaskMapFiles(inputFiles, maskFiles, numberImages)) { PrintError("Could not create the stitching masks"); - return -1; + goto end; } if (!panoStitchCreateAlphaChannels(maskFiles, alphaChannelFiles, numberImages)) { PrintError("Could not create alpha channels"); - return -1; + goto end; } // From this point on we do not need to process all files at once. This will save temporary disk space @@ -846,7 +855,7 @@ if (ptQuietFlag == 0) { if (Progress(_setProgress, tempString) == 0) { // We have to delete any temp file - return -1; + goto end; } } @@ -860,7 +869,7 @@ if (!panoStitchReplaceAlphaChannel (&inputFiles[i], &alphaChannelFiles[i], &withAlphaChannel)) { PrintError("Unable to replace alpha channel in image %d", i); - return -1; + goto end; } // we no longer need the alpha channel remove(alphaChannelFiles[i].name); @@ -875,7 +884,7 @@ if (!panoFeatherFile(&withAlphaChannel, &feathered, featherSize)) { PrintError("Unable to apply feather to image %d", i); - return -1; + goto end; } if (strcmp(withAlphaChannel.name, feathered.name) != 0) { @@ -888,11 +897,13 @@ } } + returnValue = 0; //success +end: free(maskFiles); free(alphaChannelFiles); - return 0; + return returnValue; } Modified: trunk/libpano/pttiff.h =================================================================== --- trunk/libpano/pttiff.h 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/pttiff.h 2009-10-08 02:48:06 UTC (rev 1097) @@ -45,8 +45,8 @@ void getCropInformationFromTiff(TIFF *tif, CropInfo *c); void setCropInformationInTiff(TIFF *tiffFile, CropInfo *crop_info); -int TiffGetImageParameters(TIFF *tiffFile, pt_tiff_parms *tiffData); -int TiffSetImageParameters(TIFF *tiffFile, pt_tiff_parms *tiffData); +//int TiffGetImageParameters(TIFF *tiffFile, pt_tiff_parms *tiffData); +//int TiffSetImageParameters(TIFF *tiffFile, pt_tiff_parms *tiffData); int panoTiffUnCrop(char *inputFile, char *outputFile, pano_cropping_parms *croppingParms); int panoTiffCrop(char *inputFile, char *outputFile, pano_cropping_parms *croppingParms); Modified: trunk/libpano/tiff.c =================================================================== --- trunk/libpano/tiff.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/tiff.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -1222,12 +1222,14 @@ panoTiff->tiff = TIFFOpen(fileName, "w"); if (panoTiff->tiff == NULL) { PrintError("Unable to create output file [%s]", fileName); + free(panoTiff); return NULL; } //printf("Copy metadata from %d\n", (int) metadata->cropInfo.fullWidth); if (!panoMetadataCopy(&panoTiff->metadata, metadata)) { panoTiffClose(panoTiff); + free(panoTiff); return NULL; } @@ -1238,6 +1240,7 @@ //printf("Copy metadata %d\n", (int) panoTiff->metadata.cropInfo.fullWidth); if (!panoTiffSetImageProperties(panoTiff)) { panoTiffClose(panoTiff); + free(panoTiff); return NULL; } //printf("After set image properties\n"); Modified: trunk/libpano/tools/PTblender.c =================================================================== --- trunk/libpano/tools/PTblender.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/tools/PTblender.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -69,15 +69,16 @@ int main(int argc,char *argv[]) { + int returnValue = -1; char opt; int referenceImage = 0; - fullPath *ptrInputFiles; - fullPath *ptrOutputFiles; + fullPath *ptrInputFiles = NULL; + fullPath *ptrOutputFiles = NULL; int counter; char outputPrefix[MAX_PATH_LENGTH]; char *endPtr; - int filesCount; + int filesCount = 0; char tempString[MAX_PATH_LENGTH]; int base = 0; int outputCurvesType = 0; // if 1 => create Photoshop curve files (.acv) @@ -85,8 +86,6 @@ int ptForceProcessing = 0; int ptDeleteSources = 0; - ptrInputFiles = NULL; - counter = 0; printf(PT_BLENDER_VERSION); @@ -107,21 +106,21 @@ strcpy(outputPrefix, optarg); } else { PrintError("Illegal length for output prefix"); - return -1; + goto end; } break; case 'k': referenceImage = strtol(optarg, &endPtr, 10); if (errno != 0) { PrintError("Invalid integer in -k option"); - return -1; + goto end; } break; case 't': typeCorrection = strtol(optarg, &endPtr, 10); if (errno != 0 || (typeCorrection < 0 || typeCorrection > 2)) { PrintError("Invalid integer in -t option"); - return -1; + goto end; } break; case 'f': @@ -132,14 +131,14 @@ case 'c': if (outputCurvesType == CB_OUTPUT_CURVE_ARBITRARY) { PrintError("Can't use both -c and -m options"); - return -1; + goto end; } outputCurvesType = CB_OUTPUT_CURVE_SMOOTH; break; case 'm': if (outputCurvesType == CB_OUTPUT_CURVE_SMOOTH) { PrintError("Can't use both -c and -m options"); - return -1; + goto end; } outputCurvesType = CB_OUTPUT_CURVE_ARBITRARY; break; @@ -148,7 +147,8 @@ break; case 'h': printf(PT_BLENDER_USAGE); - exit(0); + returnValue = 0; + goto end; default: break; } @@ -159,7 +159,7 @@ if ((ptrInputFiles = calloc(filesCount, sizeof(fullPath))) == NULL || (ptrOutputFiles = calloc(filesCount, sizeof(fullPath))) == NULL) { PrintError("Not enough memory"); - return -1; + goto end; } base = optind; @@ -170,31 +170,31 @@ if (StringtoFullPath(&ptrInputFiles[optind-base], currentParm) !=0) { // success PrintError("Syntax error: Not a valid pathname"); - return(-1); + goto end; } } if (filesCount <= 0) { PrintError("No files specified in the command line"); fprintf(stderr, PT_BLENDER_USAGE); - return -1; + goto end; } if (referenceImage < 0 || referenceImage >= filesCount) { PrintError(tempString, "Illegal reference image number %d. It should be between 0 and %d\n", referenceImage, filesCount-1); - return -1; + goto end; } //We can't output curves for type 1 or 2 corrections if (outputCurvesType != 0) { if (typeCorrection!= 0) { PrintError("Output of curves is not supported for correction type %d", typeCorrection); - return -1; + goto end; } } if (panoFileOutputNamesCreate(ptrOutputFiles, filesCount, outputPrefix) == 0) { - return -1; + goto end; } @@ -203,12 +203,12 @@ char *temp; if ((temp = panoFileExists(ptrOutputFiles, filesCount)) != NULL) { PrintError("Output filename(s) exists. Use -f to overwrite"); - return -1; + goto end; } if (!panoTiffVerifyAreCompatible(ptrInputFiles, filesCount, TRUE)) { PrintError("TIFFs are not compatible"); - return -1; + goto end; } } @@ -216,17 +216,19 @@ ColourBrightness(ptrInputFiles, ptrOutputFiles, filesCount, referenceImage, typeCorrection, outputCurvesType); - free(ptrInputFiles); - ptrInputFiles = ptrOutputFiles; - ptrOutputFiles = NULL; + returnValue = 0; // success - if (ptDeleteSources) { +end: + + if (ptDeleteSources && returnValue!=-1 && ptrInputFiles) { int i; for (i = 0; i < filesCount; i++) { remove(ptrInputFiles[i].name); } } - return 0; - + free(ptrInputFiles); + free(ptrInputFiles); + + return returnValue; } Modified: trunk/libpano/tools/PTmasker.c =================================================================== --- trunk/libpano/tools/PTmasker.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/tools/PTmasker.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -82,13 +82,14 @@ int main(int argc,char *argv[]) { + int returnValue = -1; char opt; - fullPath *ptrInputFiles; - fullPath *ptrOutputFiles; + fullPath *ptrInputFiles = NULL; + fullPath *ptrOutputFiles = NULL; int counter; char outputPrefix[MAX_PATH_LENGTH]; - int filesCount; + int filesCount = 0; int base = 0; int ptForceProcessing = 0; int feather = 0; @@ -98,8 +99,6 @@ int focusEstimationMaskType = -1; int focusEstimationSmoothingWindowSize = 0; - ptrInputFiles = NULL; - counter = 0; outputPrefix[0] = 0; @@ -118,28 +117,28 @@ feather = strtol(optarg, NULL, 10); if (errno != 0) { PrintError("Illegal value for feather"); - return -1; + goto end; } break; case 'w': focusEstimationWindowSize = strtol(optarg, NULL, 10); if (errno != 0 || focusEstimationWindowSize <= 0) { PrintError("Illegal value for focus estimation window size [%s]", optarg); - return -1; + goto end; } break; case 'm': focusEstimationMaskType = strtol(optarg, NULL, 10); if (errno != 0 || focusEstimationMaskType <0 || focusEstimationMaskType > 2) { PrintError("Illegal value for focus estimation window type [%s]", optarg); - return -1; + goto end; } break; case 's': focusEstimationSmoothingWindowSize = strtol(optarg, NULL, 10); if (errno != 0 || focusEstimationSmoothingWindowSize <= 0) { PrintError("Illegal value for focus estimation smoothing window size [%s]", optarg); - return -1; + goto end; } break; @@ -148,7 +147,7 @@ strcpy(outputPrefix, optarg); } else { PrintError("Illegal length for output prefix"); - return -1; + goto end; } break; case 'z': @@ -165,10 +164,12 @@ break; case 'h': printf(PT_MASKER_USAGE); - exit(0); + returnValue = 0; + goto end; default: printf(PT_MASKER_USAGE); - exit(1); + returnValue = 1; + goto end; break; } } @@ -184,7 +185,7 @@ if (filesCount < 1) { PrintError("No files specified in the command line"); fprintf(stderr, PT_MASKER_USAGE); - return -1; + goto end; } if (enableFocusEstimation == 0) { @@ -192,12 +193,12 @@ focusEstimationSmoothingWindowSize != 0 || focusEstimationMaskType != -1) { PrintError("You should specify -z option in order to use options -m -w or -s"); - return -1; + goto end; } } else { if (feather == 0) { PrintError("-z requires feathering (use -e)"); - return -1; + goto end; } if (filesCount == 1) { @@ -219,7 +220,7 @@ if ((ptrInputFiles = calloc(filesCount, sizeof(fullPath))) == NULL || (ptrOutputFiles = calloc(filesCount, sizeof(fullPath))) == NULL) { PrintError("Not enough memory"); - return -1; + goto end; } // GET input file names @@ -231,13 +232,13 @@ if (StringtoFullPath(&ptrInputFiles[optind-base], currentParm) !=0) { // success PrintError("Syntax error: Not a valid pathname"); - return(-1); + goto end; } } // Generate output file names if (panoFileOutputNamesCreate(ptrOutputFiles, filesCount, outputPrefix) == 0) { - return -1; + goto end; } @@ -250,12 +251,12 @@ char *temp; if ((temp = panoFileExists(ptrOutputFiles, filesCount)) != NULL) { PrintError("Output filename exists %s. Use -f to overwrite", temp); - return -1; + goto end; } if (filesCount > 1) { if (!panoTiffVerifyAreCompatible(ptrInputFiles, filesCount, TRUE)) { PrintError("Input files are not compatible. Use -f to overwrite"); - return -1; + goto end; } } } @@ -265,42 +266,40 @@ // only do feathering if (feather == 0) { PrintError("Only one file specified, nothing to do\n"); - return -1; + goto end; } - if (panoFeatherFile(ptrInputFiles, ptrOutputFiles, feather)) { - return 0; - } else - return 1; + if (!panoFeatherFile(ptrInputFiles, ptrOutputFiles, feather)) { + goto end; + } } + else { //if (filesCount > 1) + if (enableFocusEstimation) { + ZCombSetFocusWindowHalfwidth(focusEstimationWindowSize); + ZCombSetSmoothingWindowHalfwidth(focusEstimationSmoothingWindowSize); + ZCombSetMaskType(focusEstimationMaskType); + ZCombSetEnabled(); + } - if (enableFocusEstimation) { - ZCombSetFocusWindowHalfwidth(focusEstimationWindowSize); - ZCombSetSmoothingWindowHalfwidth(focusEstimationSmoothingWindowSize); - ZCombSetMaskType(focusEstimationMaskType); - ZCombSetEnabled(); + if (panoStitchReplaceMasks(ptrInputFiles, ptrOutputFiles, filesCount, + feather) != 0) { + PrintError("Could not create stitching masks"); + goto end; + } } + returnValue = 0; //success - - if (panoStitchReplaceMasks(ptrInputFiles, ptrOutputFiles, filesCount, - feather) != 0) { - PrintError("Could not create stitching masks"); - return -1; - } - - if (ptrInputFiles) free(ptrInputFiles); - if (ptrOutputFiles) free(ptrOutputFiles); - - if (ptDeleteSources) { +end: + if (ptDeleteSources && returnValue!=-1 && ptrInputFiles) { int i; for (i = 0; i < filesCount; i++) { remove(ptrInputFiles[i].name); } } + if (ptrInputFiles) free(ptrInputFiles); + if (ptrOutputFiles) free(ptrOutputFiles); - - return 0; - + return returnValue; } Modified: trunk/libpano/tools/PTmender.h =================================================================== --- trunk/libpano/tools/PTmender.h 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/tools/PTmender.h 2009-10-08 02:48:06 UTC (rev 1097) @@ -55,10 +55,10 @@ -void ReplaceExt(char *, char*); +//void ReplaceExt(char *, char*); char* Filename(fullPath* path); -int CreatePanorama(fullPath ptrImageFileNames[], int counterImageFiles, fullPath *panoFileName, fullPath *scriptFileName); -void ARGtoRGBAImage(Image *im); +//int CreatePanorama(fullPath ptrImageFileNames[], int counterImageFiles, fullPath *panoFileName, fullPath *scriptFileName); +//void ARGtoRGBAImage(Image *im); /* These functions need to be implemented */ Modified: trunk/libpano/tools/PTroller.c =================================================================== --- trunk/libpano/tools/PTroller.c 2009-10-04 22:42:02 UTC (rev 1096) +++ trunk/libpano/tools/PTroller.c 2009-10-08 02:48:06 UTC (rev 1097) @@ -61,20 +61,19 @@ int main(int argc,char *argv[]) { + int returnValue = -1; char opt; - fullPath *ptrInputFiles; - fullPath *ptrOutputFiles; + fullPath *ptrInputFiles = NULL; + fullPath *ptrOutputFiles = NULL; int counter; char flatOutputFileName[MAX_PATH_LENGTH]; - int filesCount; + int filesCount = 0; int base = 0; fullPath pathName; int ptForceProcessing = 0; int ptDeleteSources = 0; - ptrInputFiles = NULL; - counter = 0; printf(PT_ROLLER_VERSION); @@ -107,7 +106,8 @@ break; case 'h': printf(PT_ROLLER_USAGE); - exit(0); + returnValue = 0; + goto end; default: break; } @@ -118,7 +118,7 @@ if ((ptrInputFiles = calloc(filesCount, sizeof(fullPath))) == NULL || (ptrOutputFiles = calloc(filesCount, sizeof(fullPath))) == NULL) { PrintError("Not enough memory"); - return -1; + goto end; } base = optind; @@ -129,19 +129,19 @@ if (StringtoFullPath(&ptrInputFiles[optind-base], currentParm) !=0) { // success PrintError("Syntax error: Not a valid pathname"); - return(-1); + goto end; } } if (filesCount <= 0) { PrintError("No files specified in the command line"); fprintf(stderr, PT_ROLLER_USAGE); - return -1; + goto end; } if (StringtoFullPath(&pathName, flatOutputFileName) != 0) { PrintError("Not a valid output filename"); - return(-1); + goto end; } panoReplaceExt(pathName.name, ".tif"); @@ -150,32 +150,34 @@ char *temp; if ((temp = panoFileExists(&pathName, 1)) != NULL) { PrintError("Output filename exists %s", pathName.name); - return -1; + goto end; } if (!panoTiffVerifyAreCompatible(ptrInputFiles, filesCount, TRUE)) { PrintError("Input files are not compatible"); - return -1; + goto end; } } if (!panoFlattenTIFF(ptrInputFiles, filesCount, &pathName, FALSE)) { PrintError("Error while flattening TIFF-image"); - return -1; + goto end; } - if (ptrInputFiles) free(ptrInputFiles); - if (ptrOutputFiles) free(ptrOutputFiles); + returnValue = 0; // success - if (ptDeleteSources) { +end: + if (ptDeleteSources && returnValue!=-1 && ptrInputFiles) { int i; for (i = 0; i < filesCount; i++) { remove(ptrInputFiles[i].name); } } + if (ptrInputFiles) free(ptrInputFiles); + if (ptrOutputFiles) free(ptrOutputFiles); - return 0; + return returnValue; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |