diff --git a/lightningd/gossip_msg.c b/lightningd/gossip_msg.c index 4d3698851..3722b844f 100644 --- a/lightningd/gossip_msg.c +++ b/lightningd/gossip_msg.c @@ -1,12 +1,12 @@ #include #include -void fromwire_gossip_getnodes_entry(const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry) +void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry) { u8 hostnamelen; fromwire_pubkey(pptr, max, &entry->nodeid); hostnamelen = fromwire_u8(pptr, max); - entry->hostname = tal_arr(entry, char, hostnamelen); + entry->hostname = tal_arr(ctx, char, hostnamelen); fromwire_u8_array(pptr, max, (u8*)entry->hostname, hostnamelen); entry->port = fromwire_u16(pptr, max); } diff --git a/lightningd/gossip_msg.h b/lightningd/gossip_msg.h index 3a543f297..40e7843d6 100644 --- a/lightningd/gossip_msg.h +++ b/lightningd/gossip_msg.h @@ -9,7 +9,7 @@ struct gossip_getnodes_entry { u16 port; }; -void fromwire_gossip_getnodes_entry(const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry); +void fromwire_gossip_getnodes_entry(const tal_t *ctx, const u8 **pptr, size_t *max, struct gossip_getnodes_entry *entry); void towire_gossip_getnodes_entry(u8 **pptr, const struct gossip_getnodes_entry *entry); #endif /* LIGHTNING_LIGHTGNINGD_GOSSIP_MSG_H */ diff --git a/tools/generate-wire.py b/tools/generate-wire.py index f92961dc1..2d7cbbec1 100755 --- a/tools/generate-wire.py +++ b/tools/generate-wire.py @@ -23,6 +23,11 @@ type2size = { 'bool': 1 } +# These struct array helpers require a context to allocate from. +varlen_structs = [ + 'gossip_getnodes_entry', +] + class FieldType(object): def __init__(self,name): self.name = name @@ -235,8 +240,9 @@ class Message(object): subcalls.append('\t\t{}[i] = fromwire_{}(&cursor, plen);' .format(name, basetype)) else: - subcalls.append('\t\tfromwire_{}(&cursor, plen, {} + i);' - .format(basetype, name)) + ctx = "ctx, " if basetype in varlen_structs else "" + subcalls.append('\t\tfromwire_{}({}&cursor, plen, {} + i);' + .format(basetype, ctx, name)) def print_fromwire(self,is_header): ctx_arg = 'const tal_t *ctx, ' if self.has_variable_fields else ''