summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-01-29 08:53:42 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2009-01-29 08:53:42 +0100
commit77f095422316289af374a59423e3f0ccc9602ed3 (patch)
tree0e41c6bcd5e0bba49ea3bb3c7429f05a59cab6d0
parenta48dbbd42593f8ab889ad3fe678b5d67a2a824b7 (diff)
Fix a few memory leaks found using Coccinelle, http://www.emn.fr/x-info/coccinelle/
-rw-r--r--src/dimage.c4
-rw-r--r--src/ext2_dir.c1
-rw-r--r--src/fat.c16
-rw-r--r--src/file_spf.c3
-rw-r--r--src/file_tiff.c20
-rw-r--r--src/file_zip.c1
-rw-r--r--src/filegen.c6
-rw-r--r--src/phmain.c4
-rw-r--r--src/phrecn.c1
-rw-r--r--src/rfs_dir.c6
10 files changed, 56 insertions, 6 deletions
diff --git a/src/dimage.c b/src/dimage.c
index 7c1de82..81cc449 100644
--- a/src/dimage.c
+++ b/src/dimage.c
@@ -81,6 +81,7 @@ int disk_image(disk_t *disk_car, const partition_t *partition, const char *image
{
log_error("Can't create file %s.\n",image_dd);
display_message("Can't create file!\n");
+ free(buffer_disk);
return -1;
}
#ifdef HAVE_NCURSES
@@ -142,6 +143,7 @@ int disk_image(disk_t *disk_car, const partition_t *partition, const char *image
if(ind_stop==2)
{
display_message("No space left for the file image.\n");
+ free(buffer_disk);
return -2;
}
if(ind_stop)
@@ -150,11 +152,13 @@ int disk_image(disk_t *disk_car, const partition_t *partition, const char *image
display_message("Incomplete image created.\n");
else
display_message("Incomplete image created: read errors have occured.\n");
+ free(buffer_disk);
return 0;
}
if(nbr_read_error==0)
display_message("Image created successfully.\n");
else
display_message("Image created successfully but read errors have occured.\n");
+ free(buffer_disk);
return 0;
}
diff --git a/src/ext2_dir.c b/src/ext2_dir.c
index f7d8d7d..2745cb4 100644
--- a/src/ext2_dir.c
+++ b/src/ext2_dir.c
@@ -367,6 +367,7 @@ int dir_partition_ext2_init(disk_t *disk_car, const partition_t *partition, dir_
/* An alternate superblock may be used if the calling function has set an IO redirection */
if(ext2fs_open ("/dev/testdisk", 0, 0, 0, my_io_manager, &ls->current_fs)!=0)
{
+ free(my_data);
free(ls);
return -1;
}
diff --git a/src/fat.c b/src/fat.c
index d9ee496..1d114b2 100644
--- a/src/fat.c
+++ b/src/fat.c
@@ -257,7 +257,9 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con
offset_o=(cluster+cluster/2)%disk_car->sector_size;
if(disk_car->read(disk_car,2*disk_car->sector_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
{
- log_error("get_next_cluster read error\n"); return 0;
+ log_error("get_next_cluster read error\n");
+ free(buffer);
+ return 0;
}
if((cluster&1)!=0)
next_cluster=le16((*((uint16_t*)&buffer[offset_o])))>>4;
@@ -273,7 +275,9 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con
offset_o=cluster%(disk_car->sector_size/2);
if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
{
- log_error("get_next_cluster read error\n"); return 0;
+ log_error("get_next_cluster read error\n");
+ free(buffer);
+ return 0;
}
next_cluster=le16(p16[offset_o]);
free(buffer);
@@ -286,7 +290,9 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con
offset_o=cluster%(disk_car->sector_size/4);
if(disk_car->read(disk_car,disk_car->sector_size, buffer, partition->part_offset+(uint64_t)(offset+offset_s)*disk_car->sector_size)!=0)
{
- log_error("get_next_cluster read error\n"); return 0;
+ log_error("get_next_cluster read error\n");
+ free(buffer);
+ return 0;
}
/* FAT32 used 28 bits, the 4 high bits are reserved
* 0x00000000: free cluster
@@ -690,11 +696,15 @@ int comp_FAT(disk_t *disk_car,const partition_t *partition,const unsigned long i
if(disk_car->read(disk_car,read_size*disk_car->sector_size, buffer, hd_offset))
{
log_error("comp_FAT: can't read FAT1\n");
+ free(buffer2);
+ free(buffer);
return 1;
}
if(disk_car->read(disk_car,read_size*disk_car->sector_size, buffer2, hd_offset2))
{
log_error("comp_FAT: can't read FAT2\n");
+ free(buffer2);
+ free(buffer);
return 1;
}
if(memcmp(buffer,buffer2,disk_car->sector_size*read_size)!=0)
diff --git a/src/file_spf.c b/src/file_spf.c
index 027bdba..2fdf07f 100644
--- a/src/file_spf.c
+++ b/src/file_spf.c
@@ -74,7 +74,10 @@ static void file_check_spf(file_recovery_t *file_recovery)
unsigned char*buffer;
buffer=(unsigned char*)MALLOC(READ_SIZE);
if(fseek(file_recovery->handle, 0, SEEK_SET)<0)
+ {
+ free(buffer);
return;
+ }
file_recovery->file_size=0;
while(1)
{
diff --git a/src/file_tiff.c b/src/file_tiff.c
index edc506b..3701329 100644
--- a/src/file_tiff.c
+++ b/src/file_tiff.c
@@ -354,17 +354,27 @@ static uint64_t header_check_tiff_le(FILE *in, const uint32_t tiff_diroff, const
uint32_t *subifd_offsetp;
subifd_offsetp=(uint32_t *)MALLOC(nbr*sizeof(*subifd_offsetp));
if(fseek(in, le32(entry->tdir_offset), SEEK_SET) < 0)
+ {
+ free(subifd_offsetp);
return -1;
+ }
if(fread(subifd_offsetp, sizeof(*subifd_offsetp), nbr, in) != nbr)
+ {
+ free(subifd_offsetp);
return -1;
+ }
for(j=0; j<nbr; j++)
{
const uint64_t new_offset=header_check_tiff_le(in, le32(subifd_offsetp[j]), depth+1, 0);
if(new_offset==-1)
+ {
+ free(subifd_offsetp);
return -1;
+ }
if(max_offset < new_offset)
max_offset = new_offset;
}
+ free(subifd_offsetp);
}
}
break;
@@ -476,17 +486,27 @@ static uint64_t header_check_tiff_be(FILE *in, const uint32_t tiff_diroff, const
uint32_t *subifd_offsetp;
subifd_offsetp=(uint32_t *)MALLOC(nbr*sizeof(*subifd_offsetp));
if(fseek(in, be32(entry->tdir_offset), SEEK_SET) < 0)
+ {
+ free(subifd_offsetp);
return -1;
+ }
if(fread(subifd_offsetp, sizeof(*subifd_offsetp), nbr, in) != nbr)
+ {
+ free(subifd_offsetp);
return -1;
+ }
for(j=0; j<nbr; j++)
{
const uint64_t new_offset=header_check_tiff_be(in, be32(subifd_offsetp[j]), depth+1, 0);
if(new_offset==-1)
+ {
+ free(subifd_offsetp);
return -1;
+ }
if(max_offset < new_offset)
max_offset = new_offset;
}
+ free(subifd_offsetp);
}
}
break;
diff --git a/src/file_zip.c b/src/file_zip.c
index c59047f..8223281 100644
--- a/src/file_zip.c
+++ b/src/file_zip.c
@@ -161,6 +161,7 @@ static int zip_parse_file_entry(file_recovery_t *fr)
#ifdef DEBUG_ZIP
log_trace("zip: Unexpected EOF in file_entry header: %u bytes expected\n", len);
#endif
+ free(filename);
return -1;
}
filename[len]='\0';
diff --git a/src/filegen.c b/src/filegen.c
index d23a4c5..2a615b3 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -206,7 +206,10 @@ void file_search_footer(file_recovery_t *file_recovery, const unsigned char*foot
else
file_size-=read_size;
if(fseek(file_recovery->handle,file_size,SEEK_SET)<0)
+ {
+ free(buffer);
return;
+ }
taille=fread(buffer,1,read_size,file_recovery->handle);
for(i=taille-1;i>=0;i--)
{
@@ -242,7 +245,10 @@ void file_search_lc_footer(file_recovery_t *file_recovery, const unsigned char*f
else
file_size-=read_size;
if(fseek(file_recovery->handle,file_size,SEEK_SET)<0)
+ {
+ free(buffer);
return;
+ }
taille=fread(buffer,1,read_size,file_recovery->handle);
for(i=0;i<taille;i++)
buffer[i]=tolower(buffer[i]);
diff --git a/src/phmain.c b/src/phmain.c
index 6ad5e8b..f697fb5 100644
--- a/src/phmain.c
+++ b/src/phmain.c
@@ -326,7 +326,9 @@ int main( int argc, char **argv )
hd_update_all_geometry(list_disk,0,verbose);
/* Activate the cache, even if photorec has its own */
for(element_disk=list_disk;element_disk!=NULL;element_disk=element_disk->next)
- element_disk->disk=new_diskcache(element_disk->disk,testdisk_mode);
+ {
+ element_disk->disk=new_diskcache(element_disk->disk, testdisk_mode);
+ }
/* save disk parameters to rapport */
log_info("Hard disk list\n");
for(element_disk=list_disk;element_disk!=NULL;element_disk=element_disk->next)
diff --git a/src/phrecn.c b/src/phrecn.c
index cb41809..d653adc 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -462,6 +462,7 @@ static int photorec_bf(disk_t *disk_car, partition_t *partition, const int verbo
}
}
}
+ free(buffer_start);
#ifdef HAVE_NCURSES
photorec_info(stdscr, file_stats);
#endif
diff --git a/src/rfs_dir.c b/src/rfs_dir.c
index 6303dda..9772cad 100644
--- a/src/rfs_dir.c
+++ b/src/rfs_dir.c
@@ -119,10 +119,11 @@ char *dal_error(dal_t *dal) {
static int file_read(dal_t *dal, void *buff, blk_t block, blk_t count) {
uint64_t off;
unsigned int blocklen;
- my_data_t *my_data=(my_data_t*)dal->data;
+ my_data_t *my_data;
/* log_trace("reiser file_read(dal=%p,buff=%p,block=%ld, count=%ld)\n",dal,buff,block,count); */
if (!dal || !buff)
return 0;
+ my_data=(my_data_t*)dal->data;
#ifdef HAVE_DAL_T_BLOCK_SIZE
off = (uint64_t)block * (uint64_t)dal->block_size;
blocklen = count * dal->block_size;
@@ -212,9 +213,10 @@ static blk_t file_len(dal_t *dal) {
#else
static count_t file_len(dal_t *dal) {
#endif
- my_data_t *my_data=(my_data_t*)dal->data;
+ my_data_t *my_data;
/* log_trace("reiser file_len\n"); */
if (!dal) return 0;
+ my_data=(my_data_t*)dal->data;
#ifdef HAVE_DAL_T_BLOCK_SIZE
return my_data->partition->part_size / dal->block_size;
#else