Skip to content

Commit

Permalink
fix: create a new fresh string for comm
Browse files Browse the repository at this point in the history
comm had the same inner address as the original string which it was
created from (basename). This caused the original underlying bytes to
be preserved and not garbage collected.

Converting it to a byte slice and then back to a string guarantees that
a new string is created releasing the original reference.
  • Loading branch information
geyslan committed Aug 23, 2024
1 parent bd70e3b commit 95d2ff1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/proctree/proctree_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (pt *ProcessTree) FeedFromExec(feed ExecFeed) error {

execTimestamp := traceetime.NsSinceEpochToTime(feed.TimeStamp)
basename := filepath.Base(feed.CmdPath)
comm := basename[:min(len(basename), COMM_LEN)]
comm := string([]byte(basename[:min(len(basename), COMM_LEN)]))
process.GetInfo().SetNameAt(
comm,
execTimestamp,
Expand Down

0 comments on commit 95d2ff1

Please sign in to comment.