Skip to content

Commit 7897616

Browse files
committed
fix: address PR comments
1 parent b193056 commit 7897616

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

pkg/deploymentrecord/client.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ func (c *Client) doWithRetry(ctx context.Context, method, targetURL string, body
467467
continue
468468
}
469469

470-
// Drain and close response body to enable connection reuse
471-
respBody, _ := io.ReadAll(resp.Body)
470+
// Drain and close response body to enable connection reuse.
471+
// Limit to 10MB to prevent unbounded memory allocation.
472+
respBody, _ := io.ReadAll(io.LimitReader(resp.Body, 10<<20))
472473
_ = resp.Body.Close()
473474

474475
switch {
@@ -616,9 +617,16 @@ func buildClusterRequestBody(records []*Record) ([]byte, error) {
616617
deploymentRecords := []BaseRecord{}
617618

618619
for _, r := range records {
620+
if r == nil {
621+
continue
622+
}
619623
deploymentRecords = append(deploymentRecords, r.BaseRecord)
620624
}
621625

626+
if len(deploymentRecords) == 0 {
627+
return nil, nil
628+
}
629+
622630
return json.Marshal(ClusterRecordsBody{
623631
LogicalEnvironment: records[0].LogicalEnvironment,
624632
PhysicalEnvironment: records[0].PhysicalEnvironment,

0 commit comments

Comments
 (0)