Made leaner the local memory of recursive functions (because of ulimit -s)
This commit is contained in:
158
test/xorriso.c
158
test/xorriso.c
@ -3468,59 +3468,6 @@ int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at,
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_match_file(struct XorrisO *xorriso, char *to_match, char *adr,
|
||||
int flag)
|
||||
/*
|
||||
bit0= match under fsm rules: with search_mode 0 : do not accept partial match
|
||||
bit1= with xorriso->search_mode==4 : do not check for '/'
|
||||
bit2= single level bit for Xorriso_regexec()
|
||||
*/
|
||||
/* return:
|
||||
<0 error
|
||||
0 no match
|
||||
1 match
|
||||
2 match with request to break volume loop
|
||||
*/
|
||||
{
|
||||
int ret,l,failed_at;
|
||||
char *cpt;
|
||||
|
||||
l= strlen(to_match);
|
||||
if(xorriso->search_mode==0) {
|
||||
if(flag&1) {
|
||||
if(strcmp(adr,to_match)==0)
|
||||
return(2);
|
||||
} else {
|
||||
if(strncmp(adr,to_match,l)==0)
|
||||
if(adr[l]=='/'||adr[l]==0)
|
||||
return(2);
|
||||
}
|
||||
l= strlen(adr);
|
||||
if(strncmp(to_match,adr,l)==0)
|
||||
if(to_match[l]=='/'||to_match[l]==0) {
|
||||
return(1);
|
||||
}
|
||||
} else if(xorriso->search_mode==1) {
|
||||
if(strstr(to_match,adr)!=NULL)
|
||||
return(1);
|
||||
} else if(xorriso->search_mode>=2 && xorriso->search_mode<=4) {
|
||||
if(xorriso->search_mode==4 && !(flag&2)) {
|
||||
cpt= strrchr(to_match,'/');
|
||||
if(cpt==NULL)
|
||||
cpt= to_match;
|
||||
else
|
||||
cpt++;
|
||||
} else
|
||||
cpt= to_match;
|
||||
ret= Xorriso_regexec(xorriso,cpt,&failed_at,1|(flag&4));
|
||||
if(ret==0)
|
||||
return(1);
|
||||
xorriso->re_failed_at= failed_at;
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= simple readlink(): no normalization, no multi-hop
|
||||
*/
|
||||
int Xorriso_resolve_link(struct XorrisO *xorriso,
|
||||
@ -4066,10 +4013,24 @@ int Xorriso_obtain_pattern_files_x(
|
||||
int *dive_count, int flag)
|
||||
{
|
||||
int ret, failed_at, follow_mount, follow_links;
|
||||
char adr[SfileadrL], name[SfileadrL], path_data[SfileadrL], *path;
|
||||
struct DirseQ *dirseq= NULL;
|
||||
struct stat stbuf;
|
||||
dev_t dir_dev;
|
||||
char *path;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char adr[SfileadrL], name[SfileadrL], path_data[SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
char *adr= NULL, *name= NULL, *path_data= NULL;
|
||||
|
||||
adr= malloc(SfileadrL);
|
||||
name= malloc(SfileadrL);
|
||||
path_data= malloc(SfileadrL);
|
||||
if(adr==NULL || name==NULL || path_data==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &adr, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
follow_mount= (xorriso->do_follow_mount || xorriso->do_follow_pattern);
|
||||
follow_links= (xorriso->do_follow_links || xorriso->do_follow_pattern);
|
||||
@ -4154,6 +4115,16 @@ int Xorriso_obtain_pattern_files_x(
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
|
||||
#ifndef Xorriso_fat_local_meM
|
||||
if(adr!=NULL)
|
||||
free(adr);
|
||||
if(name!=NULL)
|
||||
free(name);
|
||||
if(path_data!=NULL)
|
||||
free(path_data);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
Dirseq_destroy(&dirseq,0);
|
||||
if(flag&2)
|
||||
(*dive_count)--;
|
||||
@ -4221,6 +4192,20 @@ int Xorriso_no_pattern_memory(struct XorrisO *xorriso, off_t mem, int flag)
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_no_malloc_memory(struct XorrisO *xorriso, char **to_free, int flag)
|
||||
{
|
||||
if(to_free!=NULL)
|
||||
if(*to_free!=NULL) {
|
||||
/* Eventual memory sacrifice to get on going */
|
||||
free(*to_free);
|
||||
*to_free= NULL;
|
||||
}
|
||||
sprintf(xorriso->info_text, "Out of virtual memory");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "ABORT", 0);
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_alloc_pattern_mem(struct XorrisO *xorriso, off_t mem,
|
||||
int count, char ***filev, int flag)
|
||||
{
|
||||
@ -4803,7 +4788,6 @@ int Xorriso_show_dux_subs(struct XorrisO *xorriso,
|
||||
int flag)
|
||||
{
|
||||
int i, ret, no_sort= 0, filec= 0, l, j, fc, no_dive, is_link;
|
||||
char path[SfileadrL], show_path[SfileadrL], name[SfileadrL], sfe[5*SfileadrL];
|
||||
char **filev= NULL, *namept;
|
||||
off_t sub_size, report_size, mem= 0;
|
||||
struct DirseQ *dirseq= NULL;
|
||||
@ -4811,6 +4795,22 @@ int Xorriso_show_dux_subs(struct XorrisO *xorriso,
|
||||
dev_t dir_dev;
|
||||
struct LinkiteM *own_link_stack;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char path[SfileadrL], show_path[SfileadrL], name[SfileadrL], sfe[5*SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
char *path= NULL, *show_path= NULL, *name= NULL, *sfe= NULL;
|
||||
|
||||
sfe= malloc(5*SfileadrL);
|
||||
path= malloc(SfileadrL);
|
||||
show_path= malloc(SfileadrL);
|
||||
name= malloc(SfileadrL);
|
||||
if(path==NULL || show_path==NULL || name==NULL || sfe==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
own_link_stack= link_stack;
|
||||
namept= name;
|
||||
*size= 0;
|
||||
@ -5017,6 +5017,18 @@ revoke_sorting:;
|
||||
|
||||
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);
|
||||
if(name!=NULL)
|
||||
free(name);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
Linkitem_reset_stack(&own_link_stack, link_stack, 0);
|
||||
Dirseq_destroy(&dirseq, 0);
|
||||
if(filev!=NULL) {
|
||||
@ -5314,9 +5326,27 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
int ret,is_link, no_dive;
|
||||
struct DirseQ *dirseq= NULL;
|
||||
struct stat stbuf;
|
||||
char name[SfileadrL], path[SfileadrL], sfe[5*SfileadrL], *namept;
|
||||
char abs_dir_path_data[SfileadrL], abs_path[SfileadrL], *abs_dir_path;
|
||||
struct LinkiteM *own_link_stack;
|
||||
char *abs_dir_path, *namept;
|
||||
|
||||
#ifdef Xorriso_fat_local_meM
|
||||
char name[SfileadrL], path[SfileadrL], sfe[5*SfileadrL];
|
||||
char abs_dir_path_data[SfileadrL], abs_path[SfileadrL];
|
||||
#else /* Xorriso_fat_local_meM */
|
||||
char *name= NULL, *path= NULL, *sfe= NULL;
|
||||
char *abs_dir_path_data= NULL, *abs_path= NULL;
|
||||
|
||||
sfe= malloc(5*SfileadrL);
|
||||
name= malloc(SfileadrL);
|
||||
path= malloc(SfileadrL);
|
||||
abs_dir_path_data= malloc(SfileadrL);
|
||||
abs_path= malloc(SfileadrL);
|
||||
if(name==NULL || sfe==NULL || path==NULL ||
|
||||
abs_dir_path_data==NULL || abs_path==NULL) {
|
||||
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
own_link_stack= link_stack;
|
||||
abs_dir_path= abs_dir_parm;
|
||||
@ -5411,6 +5441,20 @@ int Xorriso_findx(struct XorrisO *xorriso, struct FindjoB *job,
|
||||
|
||||
ret= 1;
|
||||
ex:;
|
||||
|
||||
#ifndef Xorriso_fat_local_meM
|
||||
if(sfe!=NULL)
|
||||
free(sfe);
|
||||
if(name!=NULL)
|
||||
free(name);
|
||||
if(path!=NULL)
|
||||
free(path);
|
||||
if(abs_dir_path_data!=NULL)
|
||||
free(abs_dir_path_data);
|
||||
if(abs_path!=NULL)
|
||||
free(abs_path);
|
||||
#endif /* ! Xorriso_fat_local_meM */
|
||||
|
||||
Dirseq_destroy(&dirseq, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
Reference in New Issue
Block a user