-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
When creating a new filter is there no a memory leek ??
int
fds_ipfix_filter_create(struct fds_ipfix_filter **ipxfil, const fds_iemgr_t *iemgr, const char *expr)
{
*ipxfil = calloc(1, sizeof(struct fds_ipfix_filter));
if (*ipxfil == NULL) {
return FDS_ERR_NOMEM;
}
(*ipxfil)->iemgr = iemgr;
fds_filter_opts_t *opts = fds_filter_create_default_opts();
if (opts == NULL) {
(*ipxfil)->error = MEMORY_ERROR;
return FDS_ERR_NOMEM;
}
fds_filter_opts_set_lookup_cb(opts, lookup_callback);
fds_filter_opts_set_const_cb(opts, const_callback);
fds_filter_opts_set_data_cb(opts, data_callback);
fds_filter_opts_set_user_ctx(opts, *ipxfil);
int rc = fds_filter_create(&(*ipxfil)->filter, expr, opts); << This copies the opts and there is no free of the opts that was allocated in this function
if (rc != FDS_OK) {
(*ipxfil)->error = fds_filter_get_error((*ipxfil)->filter);
return rc;
}
return FDS_OK;
}
If i allocate two filters and call
fds_ipfix_filter_destroy(filter);
==283998==
==283998== HEAP SUMMARY:
==283998== in use at exit: 10,957 bytes in 16 blocks
==283998== total heap usage: 73,323 allocs, 73,307 frees, 6,474,123 bytes allocated
==283998==
==283998== 6,032 (80 direct, 5,952 indirect) bytes in 2 blocks are definitely lost in loss record 9 of 9
==283998== at 0x4885250: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so)
==283998== by 0x4962A57: fds_filter_create_default_opts (opts.c:143)
==283998== by 0x496452B: fds_ipfix_filter_create (ipfix_filter.c:495)
Easiest fix
diff --git a/src/ipfix_filter/ipfix_filter.c b/src/ipfix_filter/ipfix_filter.c
index d423e2b..72dff52 100644
--- a/src/ipfix_filter/ipfix_filter.c
+++ b/src/ipfix_filter/ipfix_filter.c
@@ -503,6 +503,7 @@ fds_ipfix_filter_create(struct fds_ipfix_filter **ipxfil, const fds_iemgr_t *iem
fds_filter_opts_set_user_ctx(opts, *ipxfil);
int rc = fds_filter_create(&(*ipxfil)->filter, expr, opts);
+ fds_filter_destroy_opts(opts);
if (rc != FDS_OK) {
(*ipxfil)->error = fds_filter_get_error((*ipxfil)->filter);
return rc;
Metadata
Metadata
Assignees
Labels
No labels