summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2010-11-22 01:53:18 +0100
committerPatrick McHardy <kaber@trash.net>2010-11-22 16:04:21 +0100
commit642e927e21c5c09be6c9f4714328016dcc593557 (patch)
tree474951dd4ad67e1a5bd8192f9620e35b84a23e09
parent360ca87ffc822d6d12362a9abd1c58abb2ca0949 (diff)
dectmon: fix some memory leaks
Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--include/cli.h1
-rw-r--r--include/dectmon.h3
-rw-r--r--src/cli.c1
-rw-r--r--src/cmd-parser.y13
-rw-r--r--src/cmd-scanner.l7
-rw-r--r--src/dlc.c22
-rw-r--r--src/mac.c6
-rw-r--r--src/main.c25
-rw-r--r--src/nwk.c6
9 files changed, 74 insertions, 10 deletions
diff --git a/include/cli.h b/include/cli.h
index f288719..e34cc94 100644
--- a/include/cli.h
+++ b/include/cli.h
@@ -16,6 +16,7 @@ struct location {
};
struct parser_state {
+ void *buffer_state;
unsigned int lineno;
unsigned int column;
off_t token_offset;
diff --git a/include/dectmon.h b/include/dectmon.h
index a30b397..0b4f84c 100644
--- a/include/dectmon.h
+++ b/include/dectmon.h
@@ -34,6 +34,7 @@ struct dect_handle_priv {
bool locked;
struct dect_ari pari;
+ struct dect_fd *rawsk;
struct list_head pt_list;
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,
struct dect_msg_buf *mb);
+extern void dect_mac_dis_ind(struct dect_handle *dh, struct dect_mac_con *mc);
+
/* MAC */
struct dect_mbc {
diff --git a/src/cli.c b/src/cli.c
index c853183..7a3b727 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -177,4 +177,5 @@ void cli_exit(void)
rl_callback_handler_remove();
rl_deprep_terminal();
write_history(histfile);
+ clear_history();
}
diff --git a/src/cmd-parser.y b/src/cmd-parser.y
index 90c3aa3..5d72e95 100644
--- a/src/cmd-parser.y
+++ b/src/cmd-parser.y
@@ -80,7 +80,7 @@ static void location_update(struct location *loc, struct location *rhs, int n)
%union {
uint64_t val;
- const char *string;
+ char *string;
struct dect_handle *dh;
struct dect_ie_common *ie;
struct dect_mncc_setup_param *mncc_setup_param;
@@ -271,6 +271,8 @@ cluster : STRING
struct dect_handle_priv *priv;
priv = dect_handle_get_by_name($1);
+ free($1);
+
if (priv == NULL) {
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);
dect_mncc_setup_req(dh, call, &ipui, $4);
+ dect_ie_collection_put(dh, $4);
}
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 ')'
{
+ 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);
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);
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);
memcpy(ie->info, $3, ie->len);
+ free($3);
}
;
@@ -570,6 +580,7 @@ etp_ie_param : EMC '=' NUMBER
ie->len = strlen($3);
memcpy(ie->content, $3, ie->len);
+ free($3);
}
;
diff --git a/src/cmd-scanner.l b/src/cmd-scanner.l
index 6ad121a..7f6f72e 100644
--- a/src/cmd-scanner.l
+++ b/src/cmd-scanner.l
@@ -171,7 +171,10 @@ void scanner_push_buffer(void *scanner, const char *buffer)
struct parser_state *state = yyget_extra(scanner);
YY_BUFFER_STATE b;
+ if (state->buffer_state != NULL)
+ yy_delete_buffer(state->buffer_state, scanner);
b = yy_scan_string(buffer, scanner);
+ state->buffer_state = b;
init_pos(state);
}
@@ -188,5 +191,9 @@ void *scanner_init(struct parser_state *state)
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);
}
diff --git a/src/dlc.c b/src/dlc.c
index d294a39..fbf1117 100644
--- a/src/dlc.c
+++ b/src/dlc.c
@@ -121,6 +121,7 @@ static struct dect_msg_buf *dect_lc_reassemble(struct dect_handle *dh,
err:
lc_debug(lc, "reassembly failed\n");
+ dect_mbuf_free(dh, mb);
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);
- if (mb != NULL && mb->len > DECT_FA_HDR_SIZE) {
- dect_mbuf_pull(mb, DECT_FA_HDR_SIZE);
- dect_dl_data_ind(dh, &mc->tbc->dl, mb);
+ if (mb != NULL) {
+ if (mb->len > DECT_FA_HDR_SIZE) {
+ dect_mbuf_pull(mb, DECT_FA_HDR_SIZE);
+ 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);
+}
diff --git a/src/mac.c b/src/mac.c
index ca12aa0..adea909 100644
--- a/src/mac.c
+++ b/src/mac.c
@@ -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);
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))
dect_timer_stop(dh, tbc->timer);
+ dect_timer_free(dh, tbc->timer);
+
priv->slots[tbc->slot1] = NULL;
priv->slots[tbc->slot2] = NULL;
free(tbc);
diff --git a/src/main.c b/src/main.c
index e507113..4646940 100644
--- a/src/main.c
+++ b/src/main.c
@@ -248,12 +248,22 @@ static struct dect_handle *dectmon_open_handle(struct dect_ops *ops,
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)
{
const char *cluster[DECT_MAX_CLUSTERS] = {};
unsigned int ncluster = 0, i;
+ struct dect_handle_priv *priv, *next;
struct dect_handle *dh;
- struct dect_fd *dfd;
int optidx = 0, c;
for (;;) {
@@ -301,7 +311,7 @@ int main(int argc, char **argv)
dect_event_ops_init(&ops);
dect_dummy_ops_init(&ops);
- dect_audio_init();
+ //dect_audio_init();
cli_init(stdin);
dect_set_debug_hook(dect_debug);
@@ -311,9 +321,10 @@ int main(int argc, char **argv)
for (i = 0; i < ncluster; i++) {
dh = dectmon_open_handle(&ops, cluster[i]);
+ priv = dect_handle_priv(dh);
- dfd = dect_raw_socket(dh);
- if (dfd == NULL)
+ priv->rawsk = dect_raw_open(dh);
+ if (priv->rawsk == NULL)
pexit("dect_raw_socket");
if (scan)
@@ -321,6 +332,12 @@ int main(int argc, char **argv)
}
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();
return 0;
}
diff --git a/src/nwk.c b/src/nwk.c
index 844e487..0dcb3b7 100644
--- a/src/nwk.c
+++ b/src/nwk.c
@@ -376,9 +376,9 @@ void dect_dl_data_ind(struct dect_handle *dh, struct dect_dl *dl,
dect_mbuf_pull(mb, 2);
while (mb->len) {
if (dect_parse_sfmt_ie_header(&ie, mb) < 0)
- return;
+ goto out;
if (dect_parse_sfmt_ie(dh, ie.id, &common, &ie) < 0)
- return;
+ goto out;
if (ie.id == DECT_IE_PORTABLE_IDENTITY) {
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_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,