Skip to content

Commit

Permalink
bpftrace-compiler: close http response body
Browse files Browse the repository at this point in the history
otherwise it will leak mem and/or filedescriptor

Signed-off-by: Christoph Ostarek <[email protected]>
  • Loading branch information
christoph-zededa authored and eriknordmark committed Sep 25, 2024
1 parent 8e967ee commit f6f03a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions eve-tools/bpftrace-compiler/httpRun.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (hr *httpRun) runBpftrace(aotFile string, timeout time.Duration) error {
if err != nil {
log.Fatalf("received response %v with error %v", resp, err)
}
defer resp.Body.Close()
log.Printf("http multiform resp is %+v\n", resp)

scanner := bufio.NewScanner(resp.Body)
Expand Down
15 changes: 12 additions & 3 deletions eve-tools/bpftrace-compiler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,30 @@ func newEdgeviewCmd() *cobra.Command {
log.Fatalf("could not start edgeview for bpftrace: %v", err)
}

edgeviewHostPort := fmt.Sprintf("127.0.0.1:%d", port)
for i := 0; i < 10; i++ {
var resp *http.Response
u := url.URL{
Scheme: "http",
Host: fmt.Sprintf("127.0.0.1:%d", port),
Host: edgeviewHostPort,
Path: "/",
}
resp, err := http.Get(u.String())
resp, err = http.Get(u.String())
if err == nil {
resp.Body.Close()
}
if err != nil || resp.StatusCode != http.StatusOK {
time.Sleep(time.Second)
continue
}
break
}

hr := newHTTPRun(fmt.Sprintf("localhost:%d", port))
if err != nil {
log.Fatalf("could not reach %s: %v", edgeviewHostPort, err)
}

hr := newHTTPRun(edgeviewHostPort)
defers = append(defers, func() { hr.end(); ev.shutdown() })
hr.run(args[1], uc, *f.kernelModulesFlag, f.timeout)
},
Expand Down

0 comments on commit f6f03a6

Please sign in to comment.