use named variant when allocating msgb's

when we generate a talloc report (SIGUSR1), we can now see which system
allocated a given msgb, this helps memory leak debugging
This commit is contained in:
Harald Welte 2009-06-26 19:39:35 +02:00
parent f16571635a
commit 966636f39f
11 changed files with 22 additions and 17 deletions

View File

@ -47,7 +47,7 @@ struct msgb {
unsigned char _data[0];
};
extern struct msgb *msgb_alloc(u_int16_t size);
extern struct msgb *msgb_alloc(u_int16_t size, const char *name);
extern void msgb_free(struct msgb *m);
extern void msgb_enqueue(struct llist_head *queue, struct msgb *msg);
extern struct msgb *msgb_dequeue(struct llist_head *queue);
@ -100,9 +100,10 @@ static inline void msgb_reserve(struct msgb *msg, int len)
msg->tail += len;
}
static inline struct msgb *msgb_alloc_headroom(int size, int headroom)
static inline struct msgb *msgb_alloc_headroom(int size, int headroom,
const char *name)
{
struct msgb *msg = msgb_alloc(size);
struct msgb *msg = msgb_alloc(size, name);
if (msg)
msgb_reserve(msg, headroom);
return msg;

View File

@ -423,7 +423,8 @@ static void fill_om_fom_hdr(struct abis_om_hdr *oh, u_int8_t len,
static struct msgb *nm_msgb_alloc(void)
{
return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE);
return msgb_alloc_headroom(OM_ALLOC_SIZE, OM_HEADROOM_SIZE,
"OML");
}
/* Send a OML NM Message from BSC to BTS */

View File

@ -293,7 +293,8 @@ unsigned int get_paging_group(u_int64_t imsi, unsigned int bs_cc_chans,
static struct msgb *rsl_msgb_alloc(void)
{
return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM);
return msgb_alloc_headroom(RSL_ALLOC_SIZE, RSL_ALLOC_HEADROOM,
"RSL");
}
#define MACBLOCK_SIZE 23

View File

@ -458,7 +458,7 @@ struct msgb *e1inp_tx_ts(struct e1inp_ts *e1i_ts,
}
break;
case E1INP_TS_TYPE_TRAU:
msg = msgb_alloc(TSX_ALLOC_SIZE);
msg = msgb_alloc(TSX_ALLOC_SIZE, "TRAU_TX");
if (!msg)
return NULL;
len = subchan_mux_out(&e1i_ts->trau.mux, msg->data, 40);

View File

@ -975,7 +975,8 @@ static int encode_more(struct msgb *msg)
struct msgb *gsm48_msgb_alloc(void)
{
return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM);
return msgb_alloc_headroom(GSM48_ALLOC_SIZE, GSM48_ALLOC_HEADROOM,
"GSM 04.08");
}
int gsm48_sendmsg(struct msgb *msg)
@ -1856,7 +1857,7 @@ static int mncc_recvmsg(struct gsm_network *net, struct gsm_trans *trans,
mncc->msg_type = msg_type;
msg = msgb_alloc(sizeof(struct gsm_mncc));
msg = msgb_alloc(sizeof(struct gsm_mncc), "MNCC");
if (!msg)
return -ENOMEM;
memcpy(msg->data, mncc, sizeof(struct gsm_mncc));

View File

@ -51,7 +51,8 @@ static void *tall_gsms_ctx;
struct msgb *gsm411_msgb_alloc(void)
{
return msgb_alloc_headroom(GSM411_ALLOC_SIZE, GSM411_ALLOC_HEADROOM);
return msgb_alloc_headroom(GSM411_ALLOC_SIZE, GSM411_ALLOC_HEADROOM,
"GSM 04.11");
}
int gsm0411_sendmsg(struct msgb *msg)

View File

@ -244,7 +244,7 @@ static int handle_ts1_read(struct bsc_fd *bfd)
unsigned int ts_nr = bfd->priv_nr;
struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
struct e1inp_sign_link *link;
struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE);
struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "Abis/IP");
struct ipaccess_head *hh;
int ret;

View File

@ -96,7 +96,7 @@ static int handle_ts1_read(struct bsc_fd *bfd)
unsigned int ts_nr = bfd->priv_nr;
struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
struct e1inp_sign_link *link;
struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE);
struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "mISDN TS1");
struct sockaddr_mISDN l2addr;
struct mISDNhead *hh;
socklen_t alen;
@ -278,7 +278,7 @@ static int handle_tsX_read(struct bsc_fd *bfd)
struct e1inp_line *line = bfd->data;
unsigned int ts_nr = bfd->priv_nr;
struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
struct msgb *msg = msgb_alloc(TSX_ALLOC_SIZE);
struct msgb *msg = msgb_alloc(TSX_ALLOC_SIZE, "mISDN TSx");
struct mISDNhead *hh;
int ret;

View File

@ -29,18 +29,17 @@
static void *tall_msgb_ctx;
struct msgb *msgb_alloc(u_int16_t size)
struct msgb *msgb_alloc(u_int16_t size, const char *name)
{
struct msgb *msg;
if (!tall_msgb_ctx)
tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 1, "msgb");
msg = talloc_size(tall_msgb_ctx, sizeof(*msg) + size);
msg = _talloc_zero(tall_msgb_ctx, sizeof(*msg) + size, name);
if (!msg)
return NULL;
memset(msg, 0, sizeof(*msg)+size);
msg->data_len = size;
msg->len = 0;

View File

@ -127,7 +127,7 @@ static int handle_ser_read(struct bsc_fd *bfd)
int rc = 0;
if (!sh->rx_msg) {
sh->rx_msg = msgb_alloc(SERIAL_ALLOC_SIZE);
sh->rx_msg = msgb_alloc(SERIAL_ALLOC_SIZE, "RS232 Rx");
sh->rx_msg->l2h = NULL;
sh->rx_msg->trx = sh->bts->c0;
}

View File

@ -170,7 +170,8 @@ int trau_mux_input(struct gsm_e1_subslot *src_e1_ss,
return -EINVAL;
if (!ue->callref)
return -EINVAL;
msg = msgb_alloc(sizeof(struct gsm_trau_frame) + sizeof(tf));
msg = msgb_alloc(sizeof(struct gsm_trau_frame) + sizeof(tf),
"TRAU");
if (!msg)
return -ENOMEM;
frame = (struct gsm_trau_frame *)msg->data;