From: Philippe Waroquiers Date: Sun, 16 Oct 2016 17:20:53 +0000 (+0000) Subject: Further fixes following fix of leak in 16033 X-Git-Tag: svn/VALGRIND_3_13_0~337 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=450928f8aa539991084a3cd6b3ee08d034e2f388;p=thirdparty%2Fvalgrind.git 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 --- diff --git a/coregrind/m_initimg/initimg-darwin.c b/coregrind/m_initimg/initimg-darwin.c index 5052e8670c..9ff1745791 100644 --- a/coregrind/m_initimg/initimg-darwin.c +++ b/coregrind/m_initimg/initimg-darwin.c @@ -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; } diff --git a/coregrind/m_initimg/initimg-linux.c b/coregrind/m_initimg/initimg-linux.c index 299b73ddaf..2822f97a36 100644 --- a/coregrind/m_initimg/initimg-linux.c +++ b/coregrind/m_initimg/initimg-linux.c @@ -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; } diff --git a/coregrind/m_initimg/initimg-solaris.c b/coregrind/m_initimg/initimg-solaris.c index c48ce14823..537e527afc 100644 --- a/coregrind/m_initimg/initimg-solaris.c +++ b/coregrind/m_initimg/initimg-solaris.c @@ -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; } diff --git a/coregrind/m_mallocfree.c b/coregrind/m_mallocfree.c index f877d90524..c047d82045 100644 --- a/coregrind/m_mallocfree.c +++ b/coregrind/m_mallocfree.c @@ -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); diff --git a/coregrind/m_ume/main.c b/coregrind/m_ume/main.c index a319f4acc4..3125a8e8d1 100644 --- a/coregrind/m_ume/main.c +++ b/coregrind/m_ume/main.c @@ -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); diff --git a/coregrind/m_ume/script.c b/coregrind/m_ume/script.c index 7f6b5b652a..3ebe6d9bf1 100644 --- a/coregrind/m_ume/script.c +++ b/coregrind/m_ume/script.c @@ -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') {