pgtype DecodeText and DecodeBinary do not copy
They now take ownership of the src argument. Needed to change Scan to make a copy of []byte arguments as lib/pq apparently gives Scan a shared memory buffer.
This commit is contained in:
+4
-5
@@ -97,10 +97,7 @@ func (dst *Json) DecodeText(ci *ConnInfo, src []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
buf := make([]byte, len(src))
|
||||
copy(buf, src)
|
||||
|
||||
*dst = Json{Bytes: buf, Status: Present}
|
||||
*dst = Json{Bytes: src, Status: Present}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -135,7 +132,9 @@ func (dst *Json) Scan(src interface{}) error {
|
||||
case string:
|
||||
return dst.DecodeText(nil, []byte(src))
|
||||
case []byte:
|
||||
return dst.DecodeText(nil, src)
|
||||
srcCopy := make([]byte, len(src))
|
||||
copy(srcCopy, src)
|
||||
return dst.DecodeText(nil, srcCopy)
|
||||
}
|
||||
|
||||
return fmt.Errorf("cannot scan %T", src)
|
||||
|
||||
Reference in New Issue
Block a user