Improve memory safety with defer for event cleanup across handlers, optimize conditional logging, and bump version to v0.4.3.
Some checks failed
Go / build (push) Has been cancelled
Some checks failed
Go / build (push) Has been cancelled
This commit is contained in:
@@ -43,14 +43,16 @@ func (d *D) Export(c context.Context, w io.Writer, pubkeys ...[]byte) {
|
||||
continue
|
||||
}
|
||||
// Serialize the event to JSON and write it to the output
|
||||
defer func(ev *event.E) {
|
||||
ev.Free()
|
||||
evBuf.Reset()
|
||||
}(ev)
|
||||
if _, err = w.Write(ev.Serialize()); chk.E(err) {
|
||||
return
|
||||
}
|
||||
if _, err = w.Write([]byte{'\n'}); chk.E(err) {
|
||||
return
|
||||
}
|
||||
ev.Free()
|
||||
evBuf.Reset()
|
||||
}
|
||||
return
|
||||
},
|
||||
@@ -87,15 +89,17 @@ func (d *D) Export(c context.Context, w io.Writer, pubkeys ...[]byte) {
|
||||
if err = ev.UnmarshalBinary(evBuf); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
// Serialize the event to JSON and write it to the output
|
||||
if _, err = w.Write(ev.Serialize()); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
if _, err = w.Write([]byte{'\n'}); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
ev.Free()
|
||||
evBuf.Reset()
|
||||
// Serialize the event to JSON and write it to the output
|
||||
defer func(ev *event.E) {
|
||||
ev.Free()
|
||||
evBuf.Reset()
|
||||
}(ev)
|
||||
if _, err = w.Write(ev.Serialize()); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
if _, err = w.Write([]byte{'\n'}); chk.E(err) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return
|
||||
},
|
||||
|
||||
@@ -48,6 +48,9 @@ func TestTMarshalBinary_UnmarshalBinary(t *testing.T) {
|
||||
|
||||
// Marshal unmarshaled binary event back to JSON
|
||||
unmarshaledJSON := eb.Serialize()
|
||||
defer func(ev *E) {
|
||||
eb.Free()
|
||||
}(eb)
|
||||
|
||||
// Compare the two JSON representations
|
||||
if !utils.FastEqual(b, unmarshaledJSON) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
v0.4.2
|
||||
v0.4.3
|
||||
Reference in New Issue
Block a user