From: Frank Ch. Eigler Date: Tue, 31 Mar 2026 20:11:47 +0000 (-0400) Subject: handle REVIEW.3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c2408522dffbe84cdf5479d07a675da07b7603b;p=thirdparty%2Felfutils.git handle REVIEW.3 --- diff --git a/src/stackprof.cxx b/src/stackprof.cxx index 0534d5ad..3744d3fe 100644 --- a/src/stackprof.cxx +++ b/src/stackprof.cxx @@ -135,7 +135,7 @@ static const Dwfl_Callbacks dwfl_cfi_callbacks = // Unwind statistics for a Dwfl and associated process. struct UnwindDwflStats { Dwfl *dwfl; - char *comm; // TODO(REVIEW.3) need dtor to free? or std::string? + std::string comm; int max_frames; /* for diagnostic purposes */ int total_samples; /* for diagnostic purposes */ int lost_samples; /* for diagnostic purposes */ @@ -1129,31 +1129,33 @@ const char *UnwindStatsTable::pid_find_comm (pid_t pid) UnwindDwflStats *entry = this->pid_find_or_create(pid); if (entry == NULL) return unknown_comm; - if (entry->comm != NULL) - return entry->comm; + if (!entry->comm.empty()) + return entry->comm.c_str(); char name[64]; int i = snprintf (name, sizeof(name), "/proc/%ld/comm", (long) pid); FILE *procfile = fopen(name, "r"); + char *buf = NULL; size_t linelen = 0; if (procfile == NULL) goto fail; - i = getline(&entry->comm, &linelen, procfile); + i = getline(&buf, &linelen, procfile); if (i < 0) { - free(entry->comm); + free(buf); goto fail; } for (i = linelen - 1; i > 0; i--) - if (entry->comm[i] == '\n') - entry->comm[i] = '\0'; + if (buf[i] == '\n') + buf[i] = '\0'; + entry->comm = buf; + free(buf); fclose(procfile); goto done; fail: - entry->comm = (char *)malloc(16); - snprintf (entry->comm, 16, unknown_comm); + entry->comm = unknown_comm; done: - return entry->comm; + return entry->comm.c_str(); } Dwfl *UnwindStatsTable::pid_find_dwfl (pid_t pid)