projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed various memory leaks in GUI
[pspp]
/
src
/
language
/
stats
/
regression.q
diff --git
a/src/language/stats/regression.q
b/src/language/stats/regression.q
index 515081a4810997fe623de70ed4b769af3442ceae..bed4f79dae561bfae4ac2a57e6205f1c33ac10e5 100644
(file)
--- a/
src/language/stats/regression.q
+++ b/
src/language/stats/regression.q
@@
-191,14
+191,12
@@
reg_stats_coeff (pspp_linreg_cache * c)
double std_err;
double beta;
const char *label;
double std_err;
double beta;
const char *label;
- char *tmp;
+
const struct variable *v;
const union value *val;
const struct variable *v;
const union value *val;
- const char *val_s;
struct tab_table *t;
assert (c != NULL);
struct tab_table *t;
assert (c != NULL);
- tmp = xnmalloc (MAX_STRING, sizeof (*tmp));
n_rows = c->n_coeffs + 2;
t = tab_create (n_cols, n_rows, 0);
n_rows = c->n_coeffs + 2;
t = tab_create (n_cols, n_rows, 0);
@@
-227,10
+225,13
@@
reg_stats_coeff (pspp_linreg_cache * c)
tab_float (t, 6, 1, 0, pval, 10, 2);
for (j = 1; j <= c->n_indeps; j++)
{
tab_float (t, 6, 1, 0, pval, 10, 2);
for (j = 1; j <= c->n_indeps; j++)
{
+ struct string tstr;
+ ds_init_empty (&tstr);
+
v = pspp_coeff_get_var (c->coeff[j], 0);
label = var_to_string (v);
/* Do not overwrite the variable's name. */
v = pspp_coeff_get_var (c->coeff[j], 0);
label = var_to_string (v);
/* Do not overwrite the variable's name. */
-
strncpy (tmp, label, MAX_STRING
);
+
ds_put_cstr (&tstr, label
);
if (var_is_alpha (v))
{
/*
if (var_is_alpha (v))
{
/*
@@
-240,11
+241,11
@@
reg_stats_coeff (pspp_linreg_cache * c)
*/
val = pspp_coeff_get_value (c->coeff[j], v);
*/
val = pspp_coeff_get_value (c->coeff[j], v);
- val_s = var_get_value_name (v, val);
-
strncat (tmp, val_s, MAX_STRING
);
+
+
var_append_value_name (v, val, &tstr
);
}
}
- tab_text (t, 1, j + 1, TAB_CENTER,
tmp
);
+ tab_text (t, 1, j + 1, TAB_CENTER,
ds_cstr (&tstr)
);
/*
Regression coefficients.
*/
/*
Regression coefficients.
*/
@@
-275,10
+276,10
@@
reg_stats_coeff (pspp_linreg_cache * c)
2 * gsl_cdf_tdist_Q (fabs (t_stat),
(double) (c->n_obs - c->n_coeffs));
tab_float (t, 6, j + 1, 0, pval, 10, 2);
2 * gsl_cdf_tdist_Q (fabs (t_stat),
(double) (c->n_obs - c->n_coeffs));
tab_float (t, 6, j + 1, 0, pval, 10, 2);
+ ds_destroy (&tstr);
}
tab_title (t, _("Coefficients"));
tab_submit (t);
}
tab_title (t, _("Coefficients"));
tab_submit (t);
- free (tmp);
}
/*
}
/*
@@
-637,16
+638,16
@@
try_name (const struct dictionary *dict, const char *name)
}
static void
}
static void
-reg_get_name (const struct dictionary *dict, char name[
LONG
_NAME_LEN],
- const char prefix[
LONG
_NAME_LEN])
+reg_get_name (const struct dictionary *dict, char name[
VAR
_NAME_LEN],
+ const char prefix[
VAR
_NAME_LEN])
{
int i = 1;
{
int i = 1;
- snprintf (name,
LONG
_NAME_LEN, "%s%d", prefix, i);
+ snprintf (name,
VAR
_NAME_LEN, "%s%d", prefix, i);
while (!try_name (dict, name))
{
i++;
while (!try_name (dict, name))
{
i++;
- snprintf (name,
LONG
_NAME_LEN, "%s%d", prefix, i);
+ snprintf (name,
VAR
_NAME_LEN, "%s%d", prefix, i);
}
}
}
}
@@
-656,7
+657,7
@@
reg_save_var (struct dataset *ds, const char *prefix, trns_proc_func * f,
{
struct dictionary *dict = dataset_dict (ds);
static int trns_index = 1;
{
struct dictionary *dict = dataset_dict (ds);
static int trns_index = 1;
- char name[
LONG
_NAME_LEN];
+ char name[
VAR
_NAME_LEN];
struct variable *new_var;
struct reg_trns *t = NULL;
struct variable *new_var;
struct reg_trns *t = NULL;
@@
-782,10
+783,15
@@
reg_print_categorical_encoding (FILE * fp, pspp_linreg_cache * c)
for (j = 0; j < n_categories; j++)
{
for (j = 0; j < n_categories; j++)
{
+ struct string vstr;
const union value *val = cat_subscript_to_value (j, varlist[i]);
const union value *val = cat_subscript_to_value (j, varlist[i]);
+ ds_init_empty (&vstr);
+ var_append_value_name (varlist[i], val, &vstr);
fprintf (fp, "%s.values[%d] = \"%s\";\n\t",
var_get_name (varlist[i]), j,
fprintf (fp, "%s.values[%d] = \"%s\";\n\t",
var_get_name (varlist[i]), j,
- var_get_value_name (varlist[i], val));
+ ds_cstr (&vstr));
+
+ ds_destroy (&vstr);
}
}
fprintf (fp, "%s", reg_export_categorical_encode_2);
}
}
fprintf (fp, "%s", reg_export_categorical_encode_2);
@@
-930,6
+936,7
@@
regression_custom_export (struct lexer *lexer, struct dataset *ds UNUSED,
model_file = NULL;
else
{
model_file = NULL;
else
{
+ fh_unref (model_file);
model_file = fh_parse (lexer, FH_REF_FILE);
if (model_file == NULL)
return 0;
model_file = fh_parse (lexer, FH_REF_FILE);
if (model_file == NULL)
return 0;
@@
-950,8
+957,12
@@
cmd_regression (struct lexer *lexer, struct dataset *ds)
bool ok;
size_t i;
bool ok;
size_t i;
+ model_file = NULL;
if (!parse_regression (lexer, ds, &cmd, NULL))
if (!parse_regression (lexer, ds, &cmd, NULL))
- return CMD_FAILURE;
+ {
+ fh_unref (model_file);
+ return CMD_FAILURE;
+ }
models = xnmalloc (cmd.n_dependent, sizeof *models);
for (i = 0; i < cmd.n_dependent; i++)
models = xnmalloc (cmd.n_dependent, sizeof *models);
for (i = 0; i < cmd.n_dependent; i++)
@@
-970,6
+981,7
@@
cmd_regression (struct lexer *lexer, struct dataset *ds)
free (v_variables);
free (models);
free_regression (&cmd);
free (v_variables);
free (models);
free_regression (&cmd);
+ fh_unref (model_file);
return ok ? CMD_SUCCESS : CMD_FAILURE;
}
return ok ? CMD_SUCCESS : CMD_FAILURE;
}
@@
-1148,8
+1160,7
@@
run_regression (struct casereader *input, struct cmd_regression *cmd,
if (!v_variables)
{
if (!v_variables)
{
- dict_get_vars (dataset_dict (ds), &v_variables, &n_variables,
- 1u << DC_SYSTEM);
+ dict_get_vars (dataset_dict (ds), &v_variables, &n_variables, 0);
}
for (i = 0; i < cmd->n_dependent; i++)
}
for (i = 0; i < cmd->n_dependent; i++)