Provide full (new) struct to trait clone functions
authorMatt Corallo <git@bluematt.me>
Sun, 18 Jul 2021 02:09:45 +0000 (02:09 +0000)
committerMatt Corallo <git@bluematt.me>
Wed, 28 Jul 2021 17:06:58 +0000 (17:06 +0000)
Previously, when we went to clone a trait-implementation struct,
we'd provide only the `this_arg` void pointer, requiring that the
`this_arg` pointer be cloned into a new object while all remaining
fields are copied over exactly.

This has a few important limitations:
 * When a struct is cloned, it is not possible to set a `free`
   function to free any new data placed in `this_arg` without it
   also being set on the original struct.
 * Supertrait fields cannot be updated in the subtrait clone
   method, including the `this_arg` and `free` methods.

The first limitation prevents us from setting `free` after a clone
when the original trait may or may not have had `free` set. For
example, if the original trait was created with a `Obj_as_Trait`
method, cloned copies would never be free'd.

The second limitation prevents us from keeping the super and
subtrait `this_arg` fields in sync, in addition to limitations
similar to the above.

This resulted in Java code double-free'ing the `this_arg` field in
`InMemorySigner` objects which were accessed as both `Sign` and
`BaseSign` traits.


No differences found