Skip to content

Bug:Memory leak in freeEventList(): eventParams not freed #297

@Labreo

Description

@Labreo

Issue:

freeEventList() in events.c only frees the EventNode container but never frees the eventParams payload allocated inside createEventNode().

In createEventNode(), every event type performs two separate heap allocations:

  1. The EventNode struct itself
  2. A type-specific params struct (HarvestParams, IrrigationParams, etc.) stored in eventParams

However, freeEventList() only frees the outer node:

void freeEventList(void) {
  EventNode *curr, *prev;
  curr = gEvents;
  while (curr != NULL) {
    prev = curr;
    curr = curr->nextEvent;
    free(prev); 
  }
}

Every event loaded from the events file leaks its parameter block.

Proposed Fix:
Free the internal parameter struct before freeing the node:

while (curr != NULL) {
  prev = curr;
  curr = curr->nextEvent;
  if (prev->eventParams != NULL) {
    free(prev->eventParams);
  }
  free(prev);
}

Note:Found while trying to understand events.c in preparation for the GSoC NetCDF I/O work. Happy to submit a PR with the fix if this is actually not intended behavior.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions