Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ladspa plugin small memory leak fix #3496

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions plugins/LadspaEffect/calf/src/calf/ladspa_wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,15 @@ struct ladspa_plugin_metadata_set
LADSPA_Descriptor descriptor;
/// LADSPA descriptor for DSSI (uses a different name for the plugin, otherwise same as descriptor)
LADSPA_Descriptor descriptor_for_dssi;
char *descriptorName;
#if USE_DSSI
/// Extended DSSI descriptor (points to descriptor_for_dssi for things like name/label/port info etc.)
DSSI_Descriptor dssi_descriptor;
DSSI_Program_Descriptor dssi_default_program;

std::vector<plugin_preset> *presets;
std::vector<DSSI_Program_Descriptor> *preset_descs;
char *descriptorForDssiName;
#endif

int input_count, output_count, param_count;
Expand Down
9 changes: 7 additions & 2 deletions plugins/LadspaEffect/calf/src/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ void ladspa_plugin_metadata_set::prepare(const plugin_metadata_iface *md, LADSPA
param_count = md->get_param_count(); // XXXKF ladspa_instance<Module>::real_param_count();

const ladspa_plugin_info &plugin_info = md->get_plugin_info();
descriptorName = strdup((std::string(plugin_info.name) + " LAPSDA").c_str());
descriptor.UniqueID = plugin_info.unique_id;
descriptor.Label = plugin_info.label;
descriptor.Name = strdup((std::string(plugin_info.name) + " LADSPA").c_str());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strdup is fine. You just need to save the result somewhere else. It is not as efficient, but correctness is more important.

descriptor.Name = descriptorName;
descriptor.Maker = plugin_info.maker;
descriptor.Copyright = plugin_info.copyright;
descriptor.Properties = md->is_rt_capable() ? LADSPA_PROPERTY_HARD_RT_CAPABLE : 0;
Expand Down Expand Up @@ -422,7 +423,8 @@ void ladspa_plugin_metadata_set::prepare_dssi()
#if USE_DSSI
const ladspa_plugin_info &plugin_info = metadata->get_plugin_info();
memcpy(&descriptor_for_dssi, &descriptor, sizeof(descriptor));
descriptor_for_dssi.Name = strdup((std::string(plugin_info.name) + " DSSI").c_str());
descriptorForDssiName = strdup((std::string(plugin_info.name) + " DSSI").c_str());
descriptor_for_dssi.Name = descriptorForDssiName;
memset(&dssi_descriptor, 0, sizeof(dssi_descriptor));
dssi_descriptor.DSSI_API_Version = 1;
dssi_descriptor.LADSPA_Plugin = &descriptor_for_dssi;
Expand Down Expand Up @@ -467,14 +469,17 @@ ladspa_plugin_metadata_set::~ladspa_plugin_metadata_set()
delete []descriptor.PortNames;
delete []descriptor.PortDescriptors;
delete []descriptor.PortRangeHints;
free(descriptorName);
#if USE_DSSI
if (presets)
presets->clear();
if (preset_descs)
preset_descs->clear();
delete presets;
delete preset_descs;
free(descriptorForDssiName);
#endif
delete metadata;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

metadata is const. You should go to the point where metadata is created, make sure you keep a reference, and release it on destruction; you may need a function with __attribute__((destructor)).

}

#endif
Expand Down