mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 11:32:48 -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:
@ -258,7 +258,6 @@ struct xlfd_decomposed {
|
||||
|
||||
static struct xlfd_decomposed *xlfd_decompose(const char *xlfd)
|
||||
{
|
||||
void *mem;
|
||||
char *p, *components[14];
|
||||
struct xlfd_decomposed *dec;
|
||||
int i;
|
||||
@ -266,15 +265,14 @@ static struct xlfd_decomposed *xlfd_decompose(const char *xlfd)
|
||||
if (!xlfd)
|
||||
return NULL;
|
||||
|
||||
mem = smalloc(sizeof(struct xlfd_decomposed) + strlen(xlfd) + 1);
|
||||
p = ((char *)mem) + sizeof(struct xlfd_decomposed);
|
||||
dec = snew_plus(struct xlfd_decomposed, strlen(xlfd) + 1);
|
||||
p = snew_plus_get_aux(dec);
|
||||
strcpy(p, xlfd);
|
||||
dec = (struct xlfd_decomposed *)mem;
|
||||
|
||||
for (i = 0; i < 14; i++) {
|
||||
if (*p != '-') {
|
||||
/* Malformed XLFD: not enough '-' */
|
||||
sfree(mem);
|
||||
sfree(dec);
|
||||
return NULL;
|
||||
}
|
||||
*p++ = '\0';
|
||||
@ -283,7 +281,7 @@ static struct xlfd_decomposed *xlfd_decompose(const char *xlfd)
|
||||
}
|
||||
if (*p) {
|
||||
/* Malformed XLFD: too many '-' */
|
||||
sfree(mem);
|
||||
sfree(dec);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user