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 all 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
13 changes: 12 additions & 1 deletion 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 Expand Up @@ -117,11 +119,20 @@ struct ladspa_wrapper
return new ladspa_instance(new Module, &output, sample_rate);
}

static typename Module::metadata_class *get_metadata() {
static typename Module::metadata_class *m = new typename Module::metadata_class;
return m;
}

/// Get a wrapper singleton - used to prevent initialization order problems which were present in older versions
static ladspa_plugin_metadata_set &get() {
static ladspa_wrapper instance(new typename Module::metadata_class);
static ladspa_wrapper instance(get_metadata());
return instance.output;
}

~ladspa_wrapper() {
delete get_metadata();
}
};

};
Expand Down
8 changes: 6 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());
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,13 +469,15 @@ 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
}

Expand Down