Skip to content

Commit ec9cebb

Browse files
authored
Merge pull request #11 from membraneframework/fix-memory-leak
Fixed leaking unifex payload
2 parents 1cb9f0c + 1eece67 commit ec9cebb

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ end
2222

2323
## Usage
2424

25-
Basically this library works similarly to [libnice] except that it doesn't support some features
26-
yet (e.g. TURN servers).
27-
25+
Basically this library works similarly to [libnice].
2826
Example flow can look in the following way (this is not complete i.e. runnable example).
2927

3028
Listed functions must be invoked on both peers.

c_src/ex_libnice/native.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ static void cb_recv(NiceAgent *_agent, guint stream_id, guint component_id,
139139
UnifexPayload *payload = unifex_payload_alloc(state->env, UNIFEX_PAYLOAD_BINARY, len);
140140
memcpy(payload->data, buf, len);
141141
send_ice_payload(state->env, *state->env->reply_to, 0, stream_id, component_id, payload);
142+
unifex_payload_release(payload);
142143
}
143144

144145
UNIFEX_TERM add_stream(UnifexEnv *env, UnifexState *state,
@@ -255,7 +256,9 @@ UNIFEX_TERM get_local_credentials(UnifexEnv *env, State *state, unsigned int str
255256
memcpy(credentials + lenufrag + 1, pwd, lenpwd + 1);
256257
g_free(ufrag);
257258
g_free(pwd);
258-
return get_local_credentials_result_ok(env, credentials);
259+
UNIFEX_TERM ret = get_local_credentials_result_ok(env, credentials);
260+
unifex_free(credentials);
261+
return ret;
259262
}
260263

261264
UNIFEX_TERM set_remote_credentials(UnifexEnv *env, State *state,

lib/ex_libnice.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ defmodule ExLibnice do
521521
{:noreply, state}
522522
end
523523

524+
@impl true
525+
def terminate(_reason, %State{cnode: cnode}) do
526+
Unifex.CNode.stop(cnode)
527+
end
528+
524529
defp lookup_stun_servers(stun_servers) do
525530
Bunch.Enum.try_map(stun_servers, fn %{server_addr: addr, server_port: port} ->
526531
case lookup_addr(addr) do

0 commit comments

Comments
 (0)