erlang
/
osmo-map-masq
Archived
4
0
Fork 0

sccp_node: Add _err responses, fix a memleak and bug in the split_udt method

the split_udt was reallocating an empty header and payload
in the send_empty label that was always used..
This commit is contained in:
Holger Hans Peter Freyther 2010-08-03 03:22:58 +08:00
parent 9addf6e44f
commit 817a760217
1 changed files with 18 additions and 9 deletions

View File

@ -82,7 +82,6 @@ static void copy_addr(struct sockaddr_sccp *addr, const struct osmo_erl_addr *so
static int split_udt(int fd, ETERM *fromp, ETERM *argp)
{
struct msgb *msg = NULL;
char null;
ETERM *resp, *hdr, *data;
if (!ERL_IS_BINARY(argp)) {
@ -92,7 +91,7 @@ static int split_udt(int fd, ETERM *fromp, ETERM *argp)
if (ERL_BIN_SIZE(argp) == 0) {
printf("Empty input.\n");
goto send_empty;
goto error;
} else {
struct sccp_parse_result result;
struct osmo_erl_udt sccp_hdr;
@ -109,14 +108,10 @@ static int split_udt(int fd, ETERM *fromp, ETERM *argp)
data = erl_mk_binary((const char *) msg->l3h, result.data_len);
} else {
printf("Failed to parse the header.\n");
goto send_empty;
goto error;
}
}
send_empty:
hdr = erl_mk_binary(&null, 0);
data = erl_mk_binary(&null, 0);
resp = erl_format("{~a, {~w, ~w}}", UDT_SPLIT_RES, hdr, data);
erl_send(fd, fromp, resp);
erl_free_term(resp);
@ -127,6 +122,12 @@ send_empty:
msgb_free(msg);
return 0;
error:
resp = erl_format("{~a, 23}", UDT_SPLIT_ERR);
erl_send(fd, fromp, resp);
erl_free_term(resp);
return -1;
}
/**
@ -158,21 +159,29 @@ static int wrap_udt(int fd, ETERM *fromp, ETERM *argp)
ERL_BIN_PTR(payload), ERL_BIN_SIZE(payload));
if (!msg) {
printf("Failed to create a UDT packet...\n");
goto free_data;
goto error;
}
data = erl_mk_binary((const char * )msg->l2h, msgb_l2len(msg));
resp = erl_format("{~a, ~w}", UDT_WRAP_RES, data);
erl_send(fd, fromp, resp);
free_data:
erl_free_term(resp);
erl_free_term(data);
erl_free_term(hdr);
erl_free_term(payload);
if (msg)
msgb_free(msg);
return 0;
error:
resp = erl_format("{~a, 23}", UDT_WRAP_ERR);
erl_send(fd, fromp, resp);
erl_free_term(resp);
erl_free_term(hdr);
erl_free_term(payload);
return -1;
}
static int create_listen_socket(int port)