dectmon: fix some memory leaks
Signed-off-by: Patrick McHardy <kaber@trash.net>
This commit is contained in:
parent
360ca87ffc
commit
642e927e21
|
@ -16,6 +16,7 @@ struct location {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct parser_state {
|
struct parser_state {
|
||||||
|
void *buffer_state;
|
||||||
unsigned int lineno;
|
unsigned int lineno;
|
||||||
unsigned int column;
|
unsigned int column;
|
||||||
off_t token_offset;
|
off_t token_offset;
|
||||||
|
|
|
@ -34,6 +34,7 @@ struct dect_handle_priv {
|
||||||
bool locked;
|
bool locked;
|
||||||
struct dect_ari pari;
|
struct dect_ari pari;
|
||||||
|
|
||||||
|
struct dect_fd *rawsk;
|
||||||
struct list_head pt_list;
|
struct list_head pt_list;
|
||||||
struct dect_tbc *slots[DECT_FRAME_SIZE];
|
struct dect_tbc *slots[DECT_FRAME_SIZE];
|
||||||
};
|
};
|
||||||
|
@ -97,6 +98,8 @@ extern void dect_mac_co_data_ind(struct dect_handle *dh,
|
||||||
enum dect_data_channels chan,
|
enum dect_data_channels chan,
|
||||||
struct dect_msg_buf *mb);
|
struct dect_msg_buf *mb);
|
||||||
|
|
||||||
|
extern void dect_mac_dis_ind(struct dect_handle *dh, struct dect_mac_con *mc);
|
||||||
|
|
||||||
/* MAC */
|
/* MAC */
|
||||||
|
|
||||||
struct dect_mbc {
|
struct dect_mbc {
|
||||||
|
|
|
@ -177,4 +177,5 @@ void cli_exit(void)
|
||||||
rl_callback_handler_remove();
|
rl_callback_handler_remove();
|
||||||
rl_deprep_terminal();
|
rl_deprep_terminal();
|
||||||
write_history(histfile);
|
write_history(histfile);
|
||||||
|
clear_history();
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
|
||||||
|
|
||||||
%union {
|
%union {
|
||||||
uint64_t val;
|
uint64_t val;
|
||||||
const char *string;
|
char *string;
|
||||||
struct dect_handle *dh;
|
struct dect_handle *dh;
|
||||||
struct dect_ie_common *ie;
|
struct dect_ie_common *ie;
|
||||||
struct dect_mncc_setup_param *mncc_setup_param;
|
struct dect_mncc_setup_param *mncc_setup_param;
|
||||||
|
@ -271,6 +271,8 @@ cluster : STRING
|
||||||
struct dect_handle_priv *priv;
|
struct dect_handle_priv *priv;
|
||||||
|
|
||||||
priv = dect_handle_get_by_name($1);
|
priv = dect_handle_get_by_name($1);
|
||||||
|
free($1);
|
||||||
|
|
||||||
if (priv == NULL) {
|
if (priv == NULL) {
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
|
@ -299,6 +301,7 @@ mncc_setup_req : MNCC_SETUP_REQ '(' cluster mncc_setup_param_alloc ',' mncc_set
|
||||||
|
|
||||||
call = dect_call_alloc(dh);
|
call = dect_call_alloc(dh);
|
||||||
dect_mncc_setup_req(dh, call, &ipui, $4);
|
dect_mncc_setup_req(dh, call, &ipui, $4);
|
||||||
|
dect_ie_collection_put(dh, $4);
|
||||||
}
|
}
|
||||||
|
|
||||||
mncc_setup_param_alloc :
|
mncc_setup_param_alloc :
|
||||||
|
@ -343,6 +346,9 @@ mncc_setup_param : portable_identity_ie
|
||||||
|
|
||||||
mncc_info_req : MNCC_INFO_REQ '(' cluster mncc_info_param_alloc ',' mncc_info_params ')'
|
mncc_info_req : MNCC_INFO_REQ '(' cluster mncc_info_param_alloc ',' mncc_info_params ')'
|
||||||
{
|
{
|
||||||
|
struct dect_handle *dh = $3;
|
||||||
|
|
||||||
|
dect_ie_collection_put(dh, $4);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -389,6 +395,8 @@ mnss_facility_req : MNSS_FACILITY_REQ '(' cluster mnss_param_alloc ',' mnss_para
|
||||||
|
|
||||||
sse = dect_ss_endpoint_alloc(dh, &ipui);
|
sse = dect_ss_endpoint_alloc(dh, &ipui);
|
||||||
dect_mnss_facility_req(dh, sse, $4);
|
dect_mnss_facility_req(dh, sse, $4);
|
||||||
|
dect_ie_collection_put(dh, $4);
|
||||||
|
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -438,6 +446,7 @@ portable_identity_ie_param: IPEI '=' STRING
|
||||||
struct dect_ie_portable_identity *ie = dect_ie_container(ie, $<ie>-1);
|
struct dect_ie_portable_identity *ie = dect_ie_container(ie, $<ie>-1);
|
||||||
|
|
||||||
dect_parse_ipei_string(&ie->ipui.pun.n.ipei, $3);
|
dect_parse_ipei_string(&ie->ipui.pun.n.ipei, $3);
|
||||||
|
free($3);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -462,6 +471,7 @@ keypad_ie_param : INFO '=' STRING
|
||||||
|
|
||||||
ie->len = strlen($3);
|
ie->len = strlen($3);
|
||||||
memcpy(ie->info, $3, ie->len);
|
memcpy(ie->info, $3, ie->len);
|
||||||
|
free($3);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -570,6 +580,7 @@ etp_ie_param : EMC '=' NUMBER
|
||||||
|
|
||||||
ie->len = strlen($3);
|
ie->len = strlen($3);
|
||||||
memcpy(ie->content, $3, ie->len);
|
memcpy(ie->content, $3, ie->len);
|
||||||
|
free($3);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,10 @@ void scanner_push_buffer(void *scanner, const char *buffer)
|
||||||
struct parser_state *state = yyget_extra(scanner);
|
struct parser_state *state = yyget_extra(scanner);
|
||||||
YY_BUFFER_STATE b;
|
YY_BUFFER_STATE b;
|
||||||
|
|
||||||
|
if (state->buffer_state != NULL)
|
||||||
|
yy_delete_buffer(state->buffer_state, scanner);
|
||||||
b = yy_scan_string(buffer, scanner);
|
b = yy_scan_string(buffer, scanner);
|
||||||
|
state->buffer_state = b;
|
||||||
init_pos(state);
|
init_pos(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,5 +191,9 @@ void *scanner_init(struct parser_state *state)
|
||||||
|
|
||||||
void scanner_destroy(struct parser_state *scanner)
|
void scanner_destroy(struct parser_state *scanner)
|
||||||
{
|
{
|
||||||
|
struct parser_state *state = yyget_extra(scanner);
|
||||||
|
|
||||||
|
if (state->buffer_state != NULL)
|
||||||
|
yy_delete_buffer(state->buffer_state, scanner);
|
||||||
yylex_destroy(scanner);
|
yylex_destroy(scanner);
|
||||||
}
|
}
|
||||||
|
|
18
src/dlc.c
18
src/dlc.c
|
@ -121,6 +121,7 @@ static struct dect_msg_buf *dect_lc_reassemble(struct dect_handle *dh,
|
||||||
|
|
||||||
err:
|
err:
|
||||||
lc_debug(lc, "reassembly failed\n");
|
lc_debug(lc, "reassembly failed\n");
|
||||||
|
dect_mbuf_free(dh, mb);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,8 +140,23 @@ void dect_mac_co_data_ind(struct dect_handle *dh, struct dect_mac_con *mc,
|
||||||
}
|
}
|
||||||
|
|
||||||
mb = dect_lc_reassemble(dh, mc->lc, chan, mb);
|
mb = dect_lc_reassemble(dh, mc->lc, chan, mb);
|
||||||
if (mb != NULL && mb->len > DECT_FA_HDR_SIZE) {
|
if (mb != NULL) {
|
||||||
|
if (mb->len > DECT_FA_HDR_SIZE) {
|
||||||
dect_mbuf_pull(mb, DECT_FA_HDR_SIZE);
|
dect_mbuf_pull(mb, DECT_FA_HDR_SIZE);
|
||||||
dect_dl_data_ind(dh, &mc->tbc->dl, mb);
|
dect_dl_data_ind(dh, &mc->tbc->dl, mb);
|
||||||
|
} else
|
||||||
|
dect_mbuf_free(dh, mb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dect_mac_dis_ind(struct dect_handle *dh, struct dect_mac_con *mc)
|
||||||
|
{
|
||||||
|
struct dect_lc *lc;
|
||||||
|
|
||||||
|
lc = mc->lc;
|
||||||
|
if (lc == NULL)
|
||||||
|
return;
|
||||||
|
if (lc->rx_buf != NULL)
|
||||||
|
dect_mbuf_free(dh, lc->rx_buf);
|
||||||
|
free(lc);
|
||||||
|
}
|
||||||
|
|
|
@ -538,8 +538,14 @@ static void dect_tbc_release(struct dect_handle *dh, struct dect_tbc *tbc)
|
||||||
struct dect_handle_priv *priv = dect_handle_priv(dh);
|
struct dect_handle_priv *priv = dect_handle_priv(dh);
|
||||||
|
|
||||||
tbc_log(tbc, "release\n");
|
tbc_log(tbc, "release\n");
|
||||||
|
|
||||||
|
dect_mac_dis_ind(dh, &tbc->mbc[DECT_MODE_FP].mc);
|
||||||
|
dect_mac_dis_ind(dh, &tbc->mbc[DECT_MODE_PP].mc);
|
||||||
|
|
||||||
if (dect_timer_running(tbc->timer))
|
if (dect_timer_running(tbc->timer))
|
||||||
dect_timer_stop(dh, tbc->timer);
|
dect_timer_stop(dh, tbc->timer);
|
||||||
|
dect_timer_free(dh, tbc->timer);
|
||||||
|
|
||||||
priv->slots[tbc->slot1] = NULL;
|
priv->slots[tbc->slot1] = NULL;
|
||||||
priv->slots[tbc->slot2] = NULL;
|
priv->slots[tbc->slot2] = NULL;
|
||||||
free(tbc);
|
free(tbc);
|
||||||
|
|
25
src/main.c
25
src/main.c
|
@ -248,12 +248,22 @@ static struct dect_handle *dectmon_open_handle(struct dect_ops *ops,
|
||||||
return dh;
|
return dh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void dectmon_close_handle(struct dect_handle_priv *priv)
|
||||||
|
{
|
||||||
|
struct dect_handle *dh = priv->dh;
|
||||||
|
|
||||||
|
if (dect_timer_running(priv->lock_timer))
|
||||||
|
dect_timer_stop(dh, priv->lock_timer);
|
||||||
|
dect_timer_free(dh, priv->lock_timer);
|
||||||
|
dect_close_handle(dh);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *cluster[DECT_MAX_CLUSTERS] = {};
|
const char *cluster[DECT_MAX_CLUSTERS] = {};
|
||||||
unsigned int ncluster = 0, i;
|
unsigned int ncluster = 0, i;
|
||||||
|
struct dect_handle_priv *priv, *next;
|
||||||
struct dect_handle *dh;
|
struct dect_handle *dh;
|
||||||
struct dect_fd *dfd;
|
|
||||||
int optidx = 0, c;
|
int optidx = 0, c;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
@ -301,7 +311,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
dect_event_ops_init(&ops);
|
dect_event_ops_init(&ops);
|
||||||
dect_dummy_ops_init(&ops);
|
dect_dummy_ops_init(&ops);
|
||||||
dect_audio_init();
|
//dect_audio_init();
|
||||||
|
|
||||||
cli_init(stdin);
|
cli_init(stdin);
|
||||||
dect_set_debug_hook(dect_debug);
|
dect_set_debug_hook(dect_debug);
|
||||||
|
@ -311,9 +321,10 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
for (i = 0; i < ncluster; i++) {
|
for (i = 0; i < ncluster; i++) {
|
||||||
dh = dectmon_open_handle(&ops, cluster[i]);
|
dh = dectmon_open_handle(&ops, cluster[i]);
|
||||||
|
priv = dect_handle_priv(dh);
|
||||||
|
|
||||||
dfd = dect_raw_socket(dh);
|
priv->rawsk = dect_raw_open(dh);
|
||||||
if (dfd == NULL)
|
if (priv->rawsk == NULL)
|
||||||
pexit("dect_raw_socket");
|
pexit("dect_raw_socket");
|
||||||
|
|
||||||
if (scan)
|
if (scan)
|
||||||
|
@ -321,6 +332,12 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
dect_event_loop();
|
dect_event_loop();
|
||||||
|
|
||||||
|
list_for_each_entry_safe(priv, next, &dect_handles, list) {
|
||||||
|
dect_raw_close(priv->dh, priv->rawsk);
|
||||||
|
dectmon_close_handle(priv);
|
||||||
|
}
|
||||||
|
|
||||||
cli_exit();
|
cli_exit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -376,9 +376,9 @@ void dect_dl_data_ind(struct dect_handle *dh, struct dect_dl *dl,
|
||||||
dect_mbuf_pull(mb, 2);
|
dect_mbuf_pull(mb, 2);
|
||||||
while (mb->len) {
|
while (mb->len) {
|
||||||
if (dect_parse_sfmt_ie_header(&ie, mb) < 0)
|
if (dect_parse_sfmt_ie_header(&ie, mb) < 0)
|
||||||
return;
|
goto out;
|
||||||
if (dect_parse_sfmt_ie(dh, ie.id, &common, &ie) < 0)
|
if (dect_parse_sfmt_ie(dh, ie.id, &common, &ie) < 0)
|
||||||
return;
|
goto out;
|
||||||
|
|
||||||
if (ie.id == DECT_IE_PORTABLE_IDENTITY) {
|
if (ie.id == DECT_IE_PORTABLE_IDENTITY) {
|
||||||
pt = dect_pt_lookup(dh, (void *)common);
|
pt = dect_pt_lookup(dh, (void *)common);
|
||||||
|
@ -398,6 +398,8 @@ void dect_dl_data_ind(struct dect_handle *dh, struct dect_dl *dl,
|
||||||
__dect_ie_put(dh, common);
|
__dect_ie_put(dh, common);
|
||||||
dect_mbuf_pull(mb, ie.len);
|
dect_mbuf_pull(mb, ie.len);
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
|
dect_mbuf_free(dh, mb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dect_dl_u_data_ind(struct dect_handle *dh, struct dect_dl *dl, bool dir,
|
void dect_dl_u_data_ind(struct dect_handle *dh, struct dect_dl *dl, bool dir,
|
||||||
|
|
Reference in New Issue