mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 03:52:49 -05:00
New memory management macro 'snew_plus'.
This formalises my occasional habit of using a single malloc to make a block that contains a header structure and a data buffer that a field of the structure will point to, allowing it to be freed in one go later. Previously I had to do this by hand, losing the type-checking advantages of snew; now I've written an snew-style macro to do the job, plus an accessor macro to cleanly get the auxiliary buffer pointer afterwards, and switched existing instances of the pattern over to using that.
This commit is contained in:
11
sshshare.c
11
sshshare.c
@ -932,17 +932,14 @@ static void share_closing(Plug plug, const char *error_msg, int error_code,
|
||||
static void share_xchannel_add_message(
|
||||
struct share_xchannel *xc, int type, const void *data, int len)
|
||||
{
|
||||
unsigned char *block;
|
||||
struct share_xchannel_message *msg;
|
||||
|
||||
/*
|
||||
* Be a little tricksy here by allocating a single memory block
|
||||
* containing both the 'struct share_xchannel_message' and the
|
||||
* actual data. Simplifies freeing it later.
|
||||
* Allocate the 'struct share_xchannel_message' and the actual
|
||||
* data in one unit.
|
||||
*/
|
||||
block = smalloc(sizeof(struct share_xchannel_message) + len);
|
||||
msg = (struct share_xchannel_message *)block;
|
||||
msg->data = block + sizeof(struct share_xchannel_message);
|
||||
msg = snew_plus(struct share_xchannel_message, len);
|
||||
msg->data = snew_plus_get_aux(msg);
|
||||
msg->datalen = len;
|
||||
msg->type = type;
|
||||
memcpy(msg->data, data, len);
|
||||
|
Reference in New Issue
Block a user