Skip to content

Commit

Permalink
chore: fix jsonblob memory usage
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Cleroux <[email protected]>
  • Loading branch information
ludydoo committed Mar 26, 2024
1 parent fedb9d3 commit e59ef5d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions libvuln/jsonblob/jsonblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (l *Loader) Next() bool {
return false
}

var vs []claircore.Vulnerability
for l.err = l.dec.Decode(&l.de); l.err == nil; l.err = l.dec.Decode(&l.de) {
id := l.de.Ref
// If we just hit a new Entry, promote the current one.
Expand All @@ -84,15 +83,14 @@ func (l *Loader) Next() bool {
l.next.Fingerprint = l.de.Fingerprint
l.next.Date = l.de.Date
}
i := len(vs)
switch l.de.Kind {
case driver.VulnerabilityKind:
vs = append(vs, claircore.Vulnerability{})
if err := json.Unmarshal(l.de.Vuln.buf, &vs[i]); err != nil {
vuln := claircore.Vulnerability{}
if err := json.Unmarshal(l.de.Vuln.buf, &vuln); err != nil {
l.err = err
return false
}
l.next.Vuln = append(l.next.Vuln, &vs[i])
l.next.Vuln = append(l.next.Vuln, &vuln)
case driver.EnrichmentKind:
en := driver.EnrichmentRecord{}
if err := json.Unmarshal(l.de.Enrichment.buf, &en); err != nil {
Expand Down

0 comments on commit e59ef5d

Please sign in to comment.