mirror of
https://github.com/HDFGroup/hdf5.git
synced 2025-01-24 15:25:00 +08:00
[svn-r13560]
bug fix a malloc call with an incorrect length caused several memory problems that ultimately corrupted a name passed in a list of arguments in the h52gif tool allocated memory was not freed tested linux
This commit is contained in:
parent
b9173f64d7
commit
0975f08d7e
@ -16,7 +16,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "hdf5.h"
|
||||
#include "H5IM.h"
|
||||
#include "H5IMpublic.h"
|
||||
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
#define WIDTH (hsize_t)400
|
||||
#define HEIGHT (hsize_t)200
|
||||
#define PAL_ENTRIES 256
|
||||
#define IMAGE1_NAME "1234567"
|
||||
#define IMAGE1_NAME "12345678"
|
||||
#define PAL_NAME "palette"
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
|
@ -15,6 +15,8 @@
|
||||
#
|
||||
# HDF Utilities Test script
|
||||
|
||||
TESTFILE="$srcdir/../testfiles/h52giftst.h5"
|
||||
|
||||
# initialize errors variable
|
||||
errors=0
|
||||
|
||||
@ -28,7 +30,6 @@ TOOLTEST()
|
||||
err=0
|
||||
$RUNSERIAL ./h52gif $*
|
||||
|
||||
|
||||
if [ $err -eq 1 ]; then
|
||||
errors="` expr $errors + 1 `";
|
||||
echo "*FAILED*"
|
||||
@ -39,8 +40,8 @@ fi
|
||||
|
||||
|
||||
|
||||
TESTING "h52giftst.h5 image1.gif -i 1234567 -p palette" ;
|
||||
TOOLTEST h52giftst.h5 image1.gif -i 1234567 -p palette
|
||||
TESTING "h52giftst.h5 image1.gif -i 12345678 -p palette" ;
|
||||
TOOLTEST $TESTFILE image1.gif -i 12345678 -p palette
|
||||
|
||||
|
||||
exit $errors
|
||||
|
@ -114,8 +114,8 @@ int main(int argc , char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(image_name_arr , 0 , (size_t)MAX_NUMBER_IMAGES);
|
||||
memset(pal_name_arr , 0 , (size_t)MAX_NUMBER_IMAGES);
|
||||
memset(image_name_arr , 0 , MAX_NUMBER_IMAGES);
|
||||
memset(pal_name_arr , 0 , MAX_NUMBER_IMAGES);
|
||||
|
||||
HDFName = (CHAR *)malloc (strlen(argv[1]) + 1);
|
||||
GIFName = (CHAR *)malloc (strlen(argv[2]) + 1);
|
||||
@ -149,7 +149,8 @@ int main(int argc , char **argv)
|
||||
if (bool_is_image) {
|
||||
/* this is an image */
|
||||
/* allocate space to store the image name */
|
||||
image_name_arr[number_of_images] = (CHAR*) malloc(strlen(argv[arg_index] + 1));
|
||||
size_t len = strlen(argv[arg_index]);
|
||||
image_name_arr[number_of_images] = (CHAR*) malloc( len + 1);
|
||||
strcpy(image_name_arr[number_of_images] , argv[arg_index]);
|
||||
|
||||
/* make the palette array for this NULL */
|
||||
@ -163,7 +164,8 @@ int main(int argc , char **argv)
|
||||
/* this is a palette */
|
||||
/* allocate space to store the pal name */
|
||||
/* the palette was probably allocated for a previous image */
|
||||
pal_name_arr[number_of_images-1] = (CHAR*) malloc(strlen(argv[arg_index] + 1));
|
||||
size_t len = strlen(argv[arg_index]);
|
||||
pal_name_arr[number_of_images-1] = (CHAR*) malloc( len + 1);
|
||||
strcpy(pal_name_arr[number_of_images - 1], argv[arg_index]);
|
||||
bool_is_palette = 0;
|
||||
continue;
|
||||
@ -172,12 +174,10 @@ int main(int argc , char **argv)
|
||||
/* oops. This was not meant to happen */
|
||||
usage();
|
||||
|
||||
#if 0
|
||||
while (number_of_images--) {
|
||||
cleanup(image_name_arr[number_of_images]);
|
||||
cleanup(pal_name_arr[number_of_images]);
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -311,9 +311,9 @@ int main(int argc , char **argv)
|
||||
if (idx == 0) {
|
||||
/* Write out the GIF header and logical screen descriptor */
|
||||
if (n_images > 1) {
|
||||
fwrite("GIF89a", sizeof( char ), (size_t)6, fpGif); /* the GIF magic number */
|
||||
fwrite("GIF89a", sizeof( char ), 6, fpGif); /* the GIF magic number */
|
||||
} else {
|
||||
fwrite("GIF87a", sizeof( char ), (size_t)6, fpGif); /* the GIF magic number */
|
||||
fwrite("GIF87a", sizeof( char ), 6, fpGif); /* the GIF magic number */
|
||||
}
|
||||
|
||||
putword(RWidth, fpGif); /* screen descriptor */
|
||||
@ -335,7 +335,7 @@ int main(int argc , char **argv)
|
||||
fputc(0x21 , fpGif);
|
||||
fputc(0xFF , fpGif);
|
||||
fputc(11 , fpGif);
|
||||
fwrite("NETSCAPE2.0" , (size_t)1 , (size_t)11 , fpGif);
|
||||
fwrite("NETSCAPE2.0" , 1 , 11 , fpGif);
|
||||
fputc(3 , fpGif);
|
||||
fputc(1 , fpGif);
|
||||
fputc(0 , fpGif);
|
||||
@ -392,14 +392,17 @@ int main(int argc , char **argv)
|
||||
|
||||
fclose(fpGif);
|
||||
|
||||
#if 0
|
||||
if (HDFName != NULL)
|
||||
free(HDFName);
|
||||
if (GIFName != NULL)
|
||||
free(GIFName);
|
||||
|
||||
while(number_of_images--) {
|
||||
if (image_name_arr[number_of_images])
|
||||
free(image_name_arr[number_of_images]);
|
||||
if (pal_name_arr[number_of_images])
|
||||
free(pal_name_arr[number_of_images]);
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user