Commit ff8df1ed authored by Morten Welinder's avatar Morten Welinder

Perl: leak fixes.

Incomplete and hacky.
parent f4c57999
......@@ -11,8 +11,16 @@
#include "perl-loader.h"
static GSList *stuff_to_free;
GNM_PLUGIN_MODULE_HEADER;
void
gnm_perl_loader_free_later (gconstpointer data)
{
stuff_to_free = g_slist_prepend (stuff_to_free, (gpointer)data);
}
GType perl_get_loader_type (GOErrorInfo **ret_error);
G_MODULE_EXPORT GType
......@@ -25,6 +33,8 @@ perl_get_loader_type (GOErrorInfo **ret_error)
G_MODULE_EXPORT void
go_plugin_shutdown (GOPlugin *plugin, GOCmdContext *cc)
{
g_slist_free_full (stuff_to_free, g_free);
stuff_to_free = NULL;
}
G_MODULE_EXPORT void
......
......@@ -36,6 +36,10 @@ while (@ARGV) {
}
}
# Uncomment to force debug information
# push @cmd, '-g';
# print STDERR "# ", join (" ", @cmd), "\n";
system (@cmd);
my $code = $?;
......
......@@ -125,9 +125,10 @@ static const GnmFuncHelp help_template[] = {
{ GNM_FUNC_HELP_END }
};
static GnmFuncHelp *default_gnm_help(const char *name)
static GnmFuncHelp *
default_gnm_help(const char *name)
{
GnmFuncHelp *help = g_new (GnmFuncHelp, 3);
GnmFuncHelp *help = g_new0 (GnmFuncHelp, 3);
if (help) {
int i;
for (i = 0; i < 3; i++)
......@@ -141,12 +142,11 @@ static GnmFuncHelp *default_gnm_help(const char *name)
static GnmFuncHelp *
make_gnm_help (const char *name, int count, SV **SP)
{
gchar *help_perl_func = g_strconcat ("help_", name, NULL);
GnmFuncHelp *help = NULL;
/* We assume that the description is a Perl array of the form
(key, text, key, text, ...). */
int n = count / 2, m = 0, k, type = GNM_FUNC_HELP_END;
GnmFuncHelp *helptmp = g_new (GnmFuncHelp, n + 1);
GnmFuncHelp *helptmp = g_new0 (GnmFuncHelp, n + 1);
if (count % 2) POPs, count--;
for (k = n; k-- > 0; ) {
SV *sv = POPs;
......@@ -175,9 +175,9 @@ make_gnm_help (const char *name, int count, SV **SP)
g_free (helptmp);
} else {
/* Collect all valid entries in a new array. */
if (n == m)
if (n == m) {
help = helptmp;
else {
} else {
int i;
help = g_new (GnmFuncHelp, m+1);
for (i = 0, k = 0; k < n; k++)
......@@ -192,6 +192,10 @@ make_gnm_help (const char *name, int count, SV **SP)
if (!help) /* Provide a reasonable default. */
help = default_gnm_help (name);
gnm_perl_loader_free_later (help);
for (n = 0; help[n].type != GNM_FUNC_HELP_END; n++)
gnm_perl_loader_free_later (help[n].text);
return help;
}
......@@ -220,7 +224,7 @@ gplp_func_desc_load (GOPluginService *service,
g_print ( _("Perl error: %s\n"), SvPV (ERRSV, n_a));
while (count-- > 0) POPs;
} else {
help = make_gnm_help(name, count, SP);
help = make_gnm_help(name, count, SP);
}
PUTBACK;
......@@ -240,6 +244,7 @@ gplp_func_desc_load (GOPluginService *service,
POPs;
} else {
arg_spec = g_strdup (POPp);
gnm_perl_loader_free_later (arg_spec);
}
PUTBACK;
......
......@@ -6,4 +6,6 @@
GType gnm_perl_plugin_loader_get_type (void);
void gnm_perl_plugin_loader_register_type (GTypeModule *module);
void gnm_perl_loader_free_later (gconstpointer data);
#endif /* GNM_PERL_PLUGIN_LOADER_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment