Made leaner the local memory of recursive functions (because of ulimit -s)
This commit is contained in:
@ -744,30 +744,50 @@ int Xorriso_add_tree(struct XorrisO *xorriso, struct iso_tree_node_dir *dir,
|
||||
int ret, target_is_dir, source_is_dir, source_is_link, fret, was_failure= 0;
|
||||
int do_not_dive;
|
||||
struct DirseQ *dirseq= NULL;
|
||||
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
||||
char disk_path[2*SfileadrL], img_path[2*SfileadrL], link_target[SfileadrL];
|
||||
char *name, *img_name, *srcpt;
|
||||
struct stat stbuf, hstbuf;
|
||||
dev_t dir_dev;
|
||||
struct LinkiteM *own_link_stack;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
||||
char disk_path[2*SfileadrL], img_path[2*SfileadrL], link_target[SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
|
||||
char *sfe= NULL, *sfe2= NULL;
|
||||
char *disk_path= NULL, *img_path= NULL, *link_target= NULL;
|
||||
|
||||
/* Avoiding large local memory objects in order to save stack space */
|
||||
sfe= malloc(5*SfileadrL);
|
||||
sfe2= malloc(5*SfileadrL);
|
||||
disk_path= malloc(2*SfileadrL);
|
||||
img_path= malloc(2*SfileadrL);
|
||||
link_target= malloc(SfileadrL);
|
||||
if(sfe==NULL || sfe2==NULL || disk_path==NULL || img_path==NULL ||
|
||||
link_target==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
own_link_stack= link_stack;
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
goto ex;
|
||||
|
||||
if(lstat(disk_dir_path, &stbuf)==-1)
|
||||
goto cannot_open_dir;
|
||||
dir_dev= stbuf.st_dev;
|
||||
if(S_ISLNK(stbuf.st_mode)) {
|
||||
if(!(xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&1))))
|
||||
return(2);
|
||||
{ret= 2; goto ex;}
|
||||
if(stat(disk_dir_path, &stbuf)==-1)
|
||||
goto cannot_open_dir;
|
||||
if(dir_dev != stbuf.st_dev &&
|
||||
!(xorriso->do_follow_mount || (xorriso->do_follow_param && !(flag&1))))
|
||||
return(2);
|
||||
{ret= 2; goto ex;}
|
||||
}
|
||||
ret= Dirseq_new(&dirseq, disk_dir_path, 1);
|
||||
if(ret<0) {
|
||||
@ -933,6 +953,20 @@ was_problem:;
|
||||
|
||||
ret= 1;
|
||||
ex:
|
||||
|
||||
#ifndef Xorriso_fat_local_meM
|
||||
if(sfe!=NULL)
|
||||
free(sfe);
|
||||
if(sfe2!=NULL)
|
||||
free(sfe2);
|
||||
if(disk_path!=NULL)
|
||||
free(disk_path);
|
||||
if(img_path!=NULL)
|
||||
free(img_path);
|
||||
if(link_target!=NULL)
|
||||
free(link_target);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
Linkitem_reset_stack(&own_link_stack, link_stack, 0);
|
||||
Dirseq_destroy(&dirseq, 0);
|
||||
@ -1602,7 +1636,21 @@ int Xorriso_rmi(struct XorrisO *xorriso, void *boss_iter,
|
||||
struct iso_tree_node_dir *boss_node, *root_dir;
|
||||
struct iso_tree_iter *iter= NULL;
|
||||
struct iso_volume *volume;
|
||||
char sfe[5*SfileadrL], sub_path[2*SfileadrL], *sub_name, *name;
|
||||
char *sub_name, *name;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char sfe[5*SfileadrL], sub_path[2*SfileadrL];
|
||||
#else
|
||||
char *sfe= NULL, *sub_path= NULL;
|
||||
|
||||
/* Avoiding large local memory objects in order to save stack space */
|
||||
sfe= malloc(5*SfileadrL);
|
||||
sub_path= malloc(2*SfileadrL);
|
||||
if(sfe==NULL || sub_path==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
||||
if(ret<=0)
|
||||
@ -1617,7 +1665,7 @@ int Xorriso_rmi(struct XorrisO *xorriso, void *boss_iter,
|
||||
if(((void *) root_dir) == ((void *) victim_node)) {
|
||||
sprintf(xorriso->info_text, "May not delete root directory");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
return(0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
|
||||
if(LIBISO_ISDIR(victim_node))
|
||||
@ -1758,6 +1806,14 @@ dir_not_removed:;
|
||||
xorriso->volset_change_pending= 1;
|
||||
ret= 1+!!is_dir;
|
||||
ex:;
|
||||
|
||||
#ifndef Xorriso_fat_local_meM
|
||||
if(sfe!=NULL)
|
||||
free(sfe);
|
||||
if(sub_path!=NULL)
|
||||
free(sub_path);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
if(iter!=NULL)
|
||||
iso_tree_iter_free(iter);
|
||||
return(ret);
|
||||
@ -1833,9 +1889,24 @@ int Xorriso_show_du_subs(struct XorrisO *xorriso,
|
||||
int i, ret, no_sort= 0, filec= 0, l;
|
||||
struct iso_tree_iter *iter= NULL;
|
||||
struct iso_tree_node *node, **node_array= NULL;
|
||||
char path[SfileadrL], show_path[SfileadrL], *name, sfe[5*SfileadrL];
|
||||
char *name;
|
||||
off_t sub_size, report_size, mem= 0;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char path[SfileadrL], show_path[SfileadrL], sfe[5*SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
char *path= NULL, *show_path= NULL, *sfe= NULL;
|
||||
|
||||
sfe= malloc(5*SfileadrL);
|
||||
path= malloc(SfileadrL);
|
||||
show_path= malloc(SfileadrL);
|
||||
if(path==NULL || show_path==NULL || sfe==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
*size= 0;
|
||||
iter= iso_tree_node_children(dir_node);
|
||||
if(iter==NULL) {
|
||||
@ -1935,6 +2006,16 @@ much_too_long:;
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
|
||||
#ifndef Xorriso_fat_local_meM
|
||||
if(sfe!=NULL)
|
||||
free(sfe);
|
||||
if(path!=NULL)
|
||||
free(path);
|
||||
if(show_path!=NULL)
|
||||
free(show_path);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
if(iter!=NULL)
|
||||
iso_tree_iter_free(iter);
|
||||
if(node_array!=NULL)
|
||||
@ -2461,7 +2542,20 @@ int Xorriso_obtain_pattern_files_i(
|
||||
int ret, failed_at;
|
||||
struct iso_tree_iter *iter= NULL;
|
||||
struct iso_tree_node *node;
|
||||
char adr[SfileadrL], *name;
|
||||
char *name;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char adr[SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
char *adr= NULL;
|
||||
|
||||
adr= malloc(SfileadrL);
|
||||
if(adr==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &adr, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
|
||||
if(!(flag&2))
|
||||
*dive_count= 0;
|
||||
@ -2510,6 +2604,12 @@ int Xorriso_obtain_pattern_files_i(
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
|
||||
#ifndef Xorriso_fat_local_meM
|
||||
if(adr!=NULL)
|
||||
free(adr);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
if(flag&2)
|
||||
(*dive_count)--;
|
||||
return(ret);
|
||||
@ -2728,7 +2828,20 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
struct iso_tree_node *node;
|
||||
struct iso_volume *volume;
|
||||
struct stat stbuf;
|
||||
char *name, path[SfileadrL], sfe[5*SfileadrL];
|
||||
char *name;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char path[SfileadrL], sfe[5*SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
char *path= NULL, *sfe= NULL;
|
||||
|
||||
sfe= malloc(5*SfileadrL);
|
||||
path= malloc(SfileadrL);
|
||||
if(sfe==NULL || path==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
dir_node= (struct iso_tree_node_dir *) dir_node_generic;
|
||||
if(dir_node==NULL) {
|
||||
@ -2799,6 +2912,14 @@ int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
|
||||
ret= 1;
|
||||
ex:;
|
||||
|
||||
#ifndef Xorriso_fat_local_meM
|
||||
if(sfe!=NULL)
|
||||
free(sfe);
|
||||
if(path!=NULL)
|
||||
free(path);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
Xorriso_process_msg_queues(xorriso,0);
|
||||
if(iter!=NULL)
|
||||
iso_tree_iter_free(iter);
|
||||
|
Reference in New Issue
Block a user