From 262ec8f7d74872db5a07048c30745c5717125f58 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 29 Jul 2011 20:43:31 +0000 Subject: [PATCH] Keep a std::string in scope when accessing its c_str. The std::string was being created and deleted in a single statement, so its c_str pointer pointed to freed memory. This could be seen with valgrind nmap --exclude foo --- targets.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/targets.cc b/targets.cc index 9563de9c1..0c30a76cf 100644 --- a/targets.cc +++ b/targets.cc @@ -197,9 +197,9 @@ int load_exclude_string(addrset *excludelist, const char *s) { begin = p; while (*p != '\0' && *p != ',') p++; - const char * addr = std::string(begin, p - begin).c_str(); - if (!addrset_add_spec(excludelist,addr, o.af(), 1)){ - fatal("Invalid address specification: %s", addr); + std::string addr_str = std::string(begin, p - begin); + if (!addrset_add_spec(excludelist, addr_str.c_str(), o.af(), 1)) { + fatal("Invalid address specification: %s", addr_str.c_str()); } if (*p == '\0') break;