]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/pprof: remove tempDir when no longer needed
authorJoe Tsai <joetsai@digital-static.net>
Wed, 11 May 2016 17:23:37 +0000 (10:23 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Wed, 11 May 2016 18:25:07 +0000 (18:25 +0000)
The pprof tools properly cleans up all files it creates, but forgets
to clean up the temporary directory itself. This CL fixes that.

Fixes #13863

Change-Id: I1151c36cdad5ace7cc97e7e04001cf0149ef0f63
Reviewed-on: https://go-review.googlesource.com/23019
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/pprof/commands/commands.go
src/cmd/internal/pprof/tempfile/tempfile.go

index 5018c02af185e78caebfb0b5202e1293bd76f113..5dfbbd4a5dc8acc75e9bf7cacc5541b88f09f952 100644 (file)
@@ -197,6 +197,7 @@ func makeVizTmpDir() error {
        if err != nil {
                return err
        }
+       tempfile.DeferDelete(name)
        vizTmpDir = name
        return nil
 }
index 31c117690a1c1f2a2112e285c083d1f63d4230c3..a5706345e4395423463c7e62ba086252abfd7dbd 100644 (file)
@@ -27,18 +27,19 @@ func New(dir, prefix, suffix string) (*os.File, error) {
 var tempFiles []string
 var tempFilesMu = sync.Mutex{}
 
-// DeferDelete marks a file to be deleted by next call to Cleanup()
+// DeferDelete marks a file or directory to be deleted by next call to Cleanup.
 func DeferDelete(path string) {
        tempFilesMu.Lock()
        tempFiles = append(tempFiles, path)
        tempFilesMu.Unlock()
 }
 
-// Cleanup removes any temporary files selected for deferred cleaning.
+// Cleanup removes any temporary files or directories selected for deferred cleaning.
+// Similar to defer semantics, the nodes are deleted in LIFO order.
 func Cleanup() {
        tempFilesMu.Lock()
-       for _, f := range tempFiles {
-               os.Remove(f)
+       for i := len(tempFiles) - 1; i >= 0; i-- {
+               os.Remove(tempFiles[i])
        }
        tempFiles = nil
        tempFilesMu.Unlock()