Skip to content

Commit

Permalink
Fixed memory leaks I think
Browse files Browse the repository at this point in the history
  • Loading branch information
Griezn committed Nov 17, 2024
1 parent aca79ab commit 45e8289
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ data_t* get_next_generator(const source_t *source) {
}
generator->has_next = false;

return &generator->source.buffer;
data_t *data = malloc(sizeof(data_t));
*data = generator->source.buffer;;

return data;
}


Expand Down
4 changes: 3 additions & 1 deletion src/query.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ void execute_operator(const operator_t *operator_, const data_t *in, data_t *out
void execute_query(const query_t *query, const source_t *source, sink_t *sink)
{
data_t data = {NULL, 0, 1};
data_t* next_data;
data_t* next_data = NULL;

while ((next_data = source->get_next(source)) != NULL) {
execute_operator(query->root, next_data, &data);
sink->push_next(sink, &data);
free(next_data);
next_data = NULL;
}
}
6 changes: 5 additions & 1 deletion tests/queryTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ class QueryTestFixture : public ::testing::Test {

void TearDown() override
{
if (skip_teardown)
if (skip_teardown) {
free(gsource);
free(gsink);
return;
}

free_generator_source(gsource);
free_generator_sink(gsink);
}
Expand Down

0 comments on commit 45e8289

Please sign in to comment.