VG_(am_get_filename) returns a pointer to memory that belongs to the
address space manager. Callers should neither modify the string nor
free it (as the string resides is statically allocated memory). That
calls for a   const HChar *
The type change exposed two bugs. One in m_addrinfo.c and one in 
m_debuginfo.c. In both cases the returned string could possibly be freed later
on. So we need to strdup it first. Now fixed.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14886 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_addrinfo.c b/coregrind/m_addrinfo.c
index 290f279..7fc777b 100644
--- a/coregrind/m_addrinfo.c
+++ b/coregrind/m_addrinfo.c
@@ -293,7 +293,8 @@
          ai->Addr.SegmentKind.segkind = seg->kind;
          ai->Addr.SegmentKind.filename = NULL;
          if (seg->kind == SkFileC)
-            ai->Addr.SegmentKind.filename = VG_(am_get_filename) (seg);
+            ai->Addr.SegmentKind.filename
+               = VG_(strdup)("mc.da.skfname", VG_(am_get_filename)(seg));
          if (ai->Addr.SegmentKind.filename != NULL)
             ai->Addr.SegmentKind.filename 
                = VG_(strdup)("mc.da.skfname",
diff --git a/coregrind/m_aspacemgr/aspacemgr-linux.c b/coregrind/m_aspacemgr/aspacemgr-linux.c
index 1547397..224cb33 100644
--- a/coregrind/m_aspacemgr/aspacemgr-linux.c
+++ b/coregrind/m_aspacemgr/aspacemgr-linux.c
@@ -627,7 +627,7 @@
    has one.  The returned name's storage cannot be assumed to be
    persistent, so the caller should immediately copy the name
    elsewhere. */
-HChar* VG_(am_get_filename)( NSegment const * seg )
+const HChar* VG_(am_get_filename)( NSegment const * seg )
 {
    Int i;
    aspacem_assert(seg);
diff --git a/coregrind/m_debuginfo/debuginfo.c b/coregrind/m_debuginfo/debuginfo.c
index e8df79c..ce37e5f 100644
--- a/coregrind/m_debuginfo/debuginfo.c
+++ b/coregrind/m_debuginfo/debuginfo.c
@@ -816,7 +816,7 @@
 ULong VG_(di_notify_mmap)( Addr a, Bool allow_SkFileV, Int use_fd )
 {
    NSegment const * seg;
-   HChar*     filename;
+   const HChar* filename;
    Bool       is_rx_map, is_rw_map, is_ro_map;
    DebugInfo* di;
    Int        actual_fd, oflags;
@@ -881,7 +881,7 @@
       Bool quiet = VG_(strstr)(filename, "/var/run/nscd/") != NULL;
       if (!quiet && VG_(clo_verbosity) > 1) {
          VG_(memset)(&fake_di, 0, sizeof(fake_di));
-         fake_di.fsm.filename = filename;
+         fake_di.fsm.filename = ML_(dinfo_strdup)("di.debuginfo.nmm", filename);
          ML_(symerr)(&fake_di, True, "failed to stat64/stat this file");
       }
       return 0;
@@ -986,7 +986,8 @@
          if (sr_Err(fd) != VKI_EACCES) {
             DebugInfo fake_di;
             VG_(memset)(&fake_di, 0, sizeof(fake_di));
-            fake_di.fsm.filename = filename;
+            fake_di.fsm.filename = ML_(dinfo_strdup)("di.debuginfo.nmm",
+                                                     filename);
             ML_(symerr)(&fake_di, True,
                         "can't open file to inspect ELF header");
          }
@@ -1005,7 +1006,7 @@
    if (sr_isError(preadres)) {
       DebugInfo fake_di;
       VG_(memset)(&fake_di, 0, sizeof(fake_di));
-      fake_di.fsm.filename = filename;
+      fake_di.fsm.filename = ML_(dinfo_strdup)("di.debuginfo.nmm", filename);
       ML_(symerr)(&fake_di, True, "can't read file to inspect ELF header");
       return 0;
    }
diff --git a/include/pub_tool_aspacemgr.h b/include/pub_tool_aspacemgr.h
index 05cc1d3..a10e21f 100644
--- a/include/pub_tool_aspacemgr.h
+++ b/include/pub_tool_aspacemgr.h
@@ -144,7 +144,7 @@
    elsewhere.  This may return NULL if the file name is not known or
    for arbitrary other implementation-dependent reasons, so callers
    need to be able to handle a NULL return value. */
-extern HChar* VG_(am_get_filename)( NSegment const * );
+extern const HChar* VG_(am_get_filename)( NSegment const * );
 
 /* Is the area [start .. start+len-1] validly accessible by the 
    client with at least the permissions 'prot' ?  To find out
diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c
index 0c0bb53..4e6e28e 100644
--- a/memcheck/mc_leakcheck.c
+++ b/memcheck/mc_leakcheck.c
@@ -1634,7 +1634,7 @@
       // memory by explicitly mapping /dev/zero.
       if (seg->kind == SkFileC 
           && (VKI_S_ISCHR(seg->mode) || VKI_S_ISBLK(seg->mode))) {
-         HChar* dev_name = VG_(am_get_filename)( seg );
+         const HChar* dev_name = VG_(am_get_filename)( seg );
          if (dev_name && 0 == VG_(strcmp)(dev_name, "/dev/zero")) {
             // Don't skip /dev/zero.
          } else {