summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2016-01-23 10:29:04 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2016-01-23 10:29:04 +0100
commit7a035acdd1ab72e63af8661aad791cb59d2cb8ed (patch)
tree2c9f0c2dc819e41fea28b046520bfa9131f64a99 /src
parent0675f6f68315c76cc3019e6fa4f34575eee793e1 (diff)
Avoid a file descriptor leak when stopping and resuming PhotoRec
Diffstat (limited to 'src')
-rw-r--r--src/dfxml.c1
-rw-r--r--src/photorec.c24
-rw-r--r--src/photorec.h1
-rw-r--r--src/psearchn.c10
4 files changed, 24 insertions, 12 deletions
diff --git a/src/dfxml.c b/src/dfxml.c
index 654cc7d..ce3e79f 100644
--- a/src/dfxml.c
+++ b/src/dfxml.c
@@ -330,5 +330,6 @@ void xml_log_file_recovered(const file_recovery_t *file_recovery)
}
xml_pop("byte_runs");
xml_pop("fileobject");
+ fflush(xml_handle);
}
#endif
diff --git a/src/photorec.c b/src/photorec.c
index b05a3e8..0c2229a 100644
--- a/src/photorec.c
+++ b/src/photorec.c
@@ -635,16 +635,22 @@ int file_finish_bf(file_recovery_t *file_recovery, struct ph_param *params,
return 1;
}
-/* file_finish2()
- @param file_recovery -
- @param struct ph_param *params
- const struct ph_options *options
- @param alloc_data_t *list_search_space
+void file_recovery_aborted(file_recovery_t *file_recovery, struct ph_param *params, alloc_data_t *list_search_space)
+{
+ if(file_recovery->file_stat==NULL)
+ return ;
+ params->offset=file_recovery->location.start;
+ if(file_recovery->handle)
+ {
+ fclose(file_recovery->handle);
+ file_recovery->handle=NULL;
+ /* File is zero-length; erase it */
+ unlink(file_recovery->filename);
+ }
+ file_block_truncate_zero(file_recovery, list_search_space);
+ reset_file_recovery(file_recovery);
+}
- @returns:
- 0: file not recovered
- 1: file recovered
- */
pfstatus_t file_finish2(file_recovery_t *file_recovery, struct ph_param *params, const int paranoid, alloc_data_t *list_search_space)
{
int file_truncated;
diff --git a/src/photorec.h b/src/photorec.h
index b69f756..3e0baad 100644
--- a/src/photorec.h
+++ b/src/photorec.h
@@ -69,6 +69,7 @@ void get_prev_location_smart(alloc_data_t *list_search_space, alloc_data_t **cur
int get_prev_file_header(alloc_data_t *list_search_space, alloc_data_t **current_search_space, uint64_t *offset);
int file_finish_bf(file_recovery_t *file_recovery, struct ph_param *params,
alloc_data_t *list_search_space);
+void file_recovery_aborted(file_recovery_t *file_recovery, struct ph_param *params, alloc_data_t *list_search_space);
pfstatus_t file_finish2(file_recovery_t *file_recovery, struct ph_param *params, const int paranoid, alloc_data_t *list_search_space);
void write_stats_log(const file_stat_t *file_stats);
void update_stats(file_stat_t *file_stats, alloc_data_t *list_search_space);
diff --git a/src/psearchn.c b/src/psearchn.c
index ef094e5..c614629 100644
--- a/src/psearchn.c
+++ b/src/psearchn.c
@@ -347,9 +347,11 @@ pstatus_t photorec_aux(struct ph_param *params, const struct ph_options *options
if(ind_stop!=PSTATUS_OK)
{
log_info("PhotoRec has been stopped\n");
- current_search_space=list_search_space;
+ file_recovery_aborted(&file_recovery, params, list_search_space);
+ free(buffer_start);
+ return ind_stop;
}
- else if(file_recovered==PFSTATUS_BAD)
+ if(file_recovered==PFSTATUS_BAD)
{
if(res==DC_SCAN)
{
@@ -431,7 +433,9 @@ pstatus_t photorec_aux(struct ph_param *params, const struct ph_options *options
if(ind_stop!=PSTATUS_OK)
{
log_info("PhotoRec has been stopped\n");
- current_search_space=list_search_space;
+ file_recovery_aborted(&file_recovery, params, list_search_space);
+ free(buffer_start);
+ return ind_stop;
}
}
}