Skip to content

Commit cf775ca

Browse files
authored
Merge pull request #40 from blairsteven/less_malloc
Reduce memory allocation in g_inet_flow_full
2 parents 5a8a56b + ecfe0de commit cf775ca

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

ginetflow.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,17 @@ GInetFlow *g_inet_flow_get_full(GInetFlowTable * table,
900900
{
901901
GInetFlow packet = {.timestamp = timestamp };
902902
GInetTuple *tuple = NULL;
903+
GInetTuple tmp_tuple = { 0 };
903904
GInetFlow *flow = NULL;
904905

905-
tuple = calloc(1, sizeof(GInetTuple));
906-
907906
if (ret_tuple) {
907+
tuple = calloc(1, sizeof(GInetTuple));
908908
*ret_tuple = tuple;
909909
}
910+
else
911+
{
912+
tuple = &tmp_tuple;
913+
}
910914

911915
if (l2) {
912916
if (!flow_parse
@@ -962,11 +966,6 @@ GInetFlow *g_inet_flow_get_full(GInetFlowTable * table,
962966
flow->packets++;
963967
}
964968
exit:
965-
/* We may need to release the temporary tuple */
966-
if (!ret_tuple) {
967-
free (tuple);
968-
}
969-
970969
return flow;
971970
}
972971

0 commit comments

Comments
 (0)