Skip to content

Commit

Permalink
Correcting the opt_res clean up function and add error checking for c…
Browse files Browse the repository at this point in the history
…reating the optional results product.
  • Loading branch information
kmacdonald-stsci committed Nov 13, 2024
1 parent 10ba745 commit 3167e60
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/stcal/ramp_fitting/src/slope_fitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ add_segment_to_list(struct segment_list * segs, npy_intp start, npy_intp end);
static PyObject *
build_opt_res(struct ramp_data * rd);

static void
clean_opt_res(struct opt_res_product * opt_res);

static void
clean_pixel_ramp(struct pixel_ramp * pr);

Expand Down Expand Up @@ -1049,8 +1052,10 @@ build_opt_res(
}

/* Copy data from rd->segs to these arrays */
/* XXX check return value */
save_opt_res(&opt_res, rd);
if (save_opt_res(&opt_res, rd)) {
clean_opt_res(&opt_res);
return Py_None;
}

/* Package arrays into output tuple */
opt_res_info = Py_BuildValue("NNNNNNNNN",
Expand All @@ -1061,6 +1066,21 @@ build_opt_res(
return opt_res_info;
}

static void
clean_opt_res(
struct opt_res_product * opt_res)
{
Py_XDECREF(opt_res->slope);
Py_XDECREF(opt_res->sigslope);
Py_XDECREF(opt_res->var_p);
Py_XDECREF(opt_res->var_r);
Py_XDECREF(opt_res->yint);
Py_XDECREF(opt_res->sigyint);
Py_XDECREF(opt_res->pedestal);
Py_XDECREF(opt_res->weights);
Py_XDECREF(opt_res->cr_mag);
}

/*
* Clean up all allocated memory for a pixel ramp, except the allocated memory
* for the data structure itself.
Expand Down

0 comments on commit 3167e60

Please sign in to comment.