Skip to content

Commit dbeb8da

Browse files
committed
Remove memory leak
1 parent 48a9b4c commit dbeb8da

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

cmd/root.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"github.com/spf13/cobra"
1212
"github.com/spf13/viper"
1313
"io/ioutil"
14+
"net/http"
15+
_ "net/http/pprof"
1416
"os"
1517
"os/signal"
1618
"path/filepath"
@@ -197,6 +199,10 @@ func Execute() {
197199
}
198200

199201
func init() {
202+
go func() {
203+
log.Println(http.ListenAndServe("localhost:6060", nil))
204+
}()
205+
200206
rootCmd.PersistentFlags().StringVar(&LogLevel, "log", "info", "The log level to output")
201207
rootCmd.PersistentFlags().BoolVar(&ForceColors, "colors", false, "Force output with colors")
202208

transcoder/transcoder.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ func ReadOut(pipe io.ReadCloser, filename string, metadata *models.FileMetadata,
129129
line := make([]byte, 0)
130130
for {
131131
buffer := make([]byte, 1)
132-
_, err := pipe.Read(buffer)
132+
readCount, err := pipe.Read(buffer)
133+
134+
if readCount == 0 {
135+
break
136+
}
133137

134138
if buffer[0] != '\n' {
135139
line = append(line, buffer[0])
@@ -170,13 +174,23 @@ func ReadOut(pipe io.ReadCloser, filename string, metadata *models.FileMetadata,
170174
func ReadError(pipe io.ReadCloser) {
171175
for {
172176
buffer := make([]byte, 1)
173-
_, err := pipe.Read(buffer)
174-
os.Stderr.Write(buffer)
177+
readCount, err := pipe.Read(buffer)
178+
179+
if readCount == 0 {
180+
break
181+
}
175182

176183
if err != nil && err != io.EOF && err != os.ErrClosed && !strings.HasSuffix(err.Error(), "file already closed") {
177184
log.Errorf("Error reading stderr: %s", err)
178185
return
179186
}
187+
188+
_, err = os.Stderr.Write(buffer)
189+
190+
if err != nil {
191+
log.Errorf("Error writing to stderr: %s", err)
192+
return
193+
}
180194
}
181195
}
182196

0 commit comments

Comments
 (0)