Further fixes following fix of leak in 16033

Rerunning valgrind under valgrind shows that interp_name and interp_args
memory was freed twice.
=> reworked the way interp_name and interp_args are freed:
* free them in VG_(ii_create_image) (linux/darwin/solaris)
* everywhere else, when overriden, first free the current value
* everywhere where interp_name or interp_args are freed, set them to NULL

With this, re-selfhosting valgrind shows no leak and no corruption
for interp_name and interp_args.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16044
This commit is contained in:
Philippe Waroquiers 2016-10-16 17:20:53 +00:00
parent 4fadc6cb88
commit 450928f8aa
6 changed files with 19 additions and 31 deletions

View File

@ -428,14 +428,10 @@ Addr setup_client_stack( void* init_sp,
*ptr++ = (Addr)(argc + 1);
/* --- client argv --- */
if (info->interp_name) {
if (info->interp_name)
*ptr++ = (Addr)copy_str(&strtab, info->interp_name);
VG_(free)(info->interp_name);
}
if (info->interp_args) {
if (info->interp_args)
*ptr++ = (Addr)copy_str(&strtab, info->interp_args);
VG_(free)(info->interp_args);
}
*ptr++ = (Addr)copy_str(&strtab, VG_(args_the_exename));
@ -566,8 +562,8 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii,
// Tell aspacem about commpage, etc
record_system_memory();
VG_(free)(info.interp_name);
VG_(free)(info.interp_args);
VG_(free)(info.interp_name); info.interp_name = NULL;
VG_(free)(info.interp_args); info.interp_args = NULL;
return iifii;
}

View File

@ -584,14 +584,10 @@ Addr setup_client_stack( void* init_sp,
*ptr++ = argc + 1;
/* --- client argv --- */
if (info->interp_name) {
if (info->interp_name)
*ptr++ = (Addr)copy_str(&strtab, info->interp_name);
VG_(free)(info->interp_name);
}
if (info->interp_args) {
if (info->interp_args)
*ptr++ = (Addr)copy_str(&strtab, info->interp_args);
VG_(free)(info->interp_args);
}
*ptr++ = (Addr)copy_str(&strtab, VG_(args_the_exename));
@ -1017,8 +1013,8 @@ IIFinaliseImageInfo VG_(ii_create_image)( IICreateImageInfo iicii,
setup_client_dataseg( dseg_max_size );
}
VG_(free)(info.interp_name);
VG_(free)(info.interp_args);
VG_(free)(info.interp_name); info.interp_name = NULL;
VG_(free)(info.interp_args); info.interp_args = NULL;
return iifii;
}

View File

@ -581,14 +581,10 @@ static Addr setup_client_stack(Addr init_sp,
*ptr++ = argc;
/* Copy-out client argv. */
if (info->interp_name) {
if (info->interp_name)
*ptr++ = (Addr)copy_str(&strtab, info->interp_name);
VG_(free)(info->interp_name);
}
if (info->interp_args) {
if (info->interp_args)
*ptr++ = (Addr)copy_str(&strtab, info->interp_args);
VG_(free)(info->interp_args);
}
*ptr++ = (Addr)copy_str(&strtab, VG_(args_the_exename));
for (i = 0; i < VG_(sizeXA)(VG_(args_for_client)); i++)
@ -959,8 +955,8 @@ IIFinaliseImageInfo VG_(ii_create_image)(IICreateImageInfo iicii,
}
}
VG_(free)(info.interp_name);
VG_(free)(info.interp_args);
VG_(free)(info.interp_name); VG_(free)(info->interp_name);
VG_(free)(info.interp_args); VG_(free)(info->interp_args);
return iifii;
}

View File

@ -2098,7 +2098,7 @@ void VG_(arena_free) ( ArenaId aid, void* ptr )
/* If this is one of V's areas, check carefully the block we're
getting back. This picks up simple block-end overruns. */
if (aid != VG_AR_CLIENT)
vg_assert(blockSane(a, b));
vg_assert(is_inuse_block(b) && blockSane(a, b));
b_bszB = get_bszB(b);
b_pszB = bszB_to_pszB(a, b_bszB);

View File

@ -223,9 +223,9 @@ static Int do_exec_shell_followup(Int ret, const HChar* exe_name, ExeInfo* info)
// Looks like a script. Run it with /bin/sh. This includes
// zero-length files.
VG_(free)(info->interp_name);
info->interp_name = VG_(strdup)("ume.desf.1", default_interp_name);
info->interp_args = NULL;
VG_(free)(info->interp_args); info->interp_args = NULL;
if (info->argv && info->argv[0] != NULL)
info->argv[0] = exe_name;
@ -281,9 +281,9 @@ static Int do_exec_shell_followup(Int ret, const HChar* exe_name, ExeInfo* info)
Int VG_(do_exec)(const HChar* exe_name, ExeInfo* info)
{
Int ret;
info->interp_name = NULL;
info->interp_args = NULL;
VG_(free)(info->interp_name); info->interp_name = NULL;
VG_(free)(info->interp_args); info->interp_args = NULL;
ret = VG_(do_exec_inner)(exe_name, info);

View File

@ -115,7 +115,7 @@ Int VG_(load_script)(Int fd, const HChar* name, ExeInfo* info)
cp++;
*cp = '\0';
}
VG_(free)(info->interp_name);
info->interp_name = VG_(strdup)("ume.ls.1", interp);
vg_assert(NULL != info->interp_name);
if (arg != NULL && *arg != '\0') {