Skip to content

Commit e51400c

Browse files
committed
Fixed one possible memory leak and added explicit initializers to the variables with non-trivial initialization.
1 parent 9bd89e3 commit e51400c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cardinality_hooks.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ aqo_set_baserel_rows_estimate(PlannerInfo *root, RelOptInfo *rel)
124124
double predicted;
125125
Oid relid;
126126
List *relids;
127-
List *selectivities;
127+
List *selectivities = NULL;
128128

129129
if (use_aqo || learn_aqo)
130130
selectivities = get_selectivities(root, rel->baserestrictinfo, 0,
@@ -163,10 +163,10 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
163163
List *param_clauses)
164164
{
165165
double predicted;
166-
Oid relid;
167-
List *relids;
168-
List *allclauses;
169-
List *selectivities;
166+
Oid relid = InvalidOid;
167+
List *relids = NULL;
168+
List *allclauses = NULL;
169+
List *selectivities = NULL;
170170
ListCell *l;
171171
ListCell *l2;
172172
int nargs;
@@ -239,7 +239,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
239239
List *selectivities;
240240
List *inner_selectivities;
241241
List *outer_selectivities;
242-
List *current_selectivities;
242+
List *current_selectivities = NULL;
243243

244244
if (use_aqo || learn_aqo)
245245
current_selectivities = get_selectivities(root, restrictlist, 0,
@@ -302,7 +302,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
302302
List *selectivities;
303303
List *inner_selectivities;
304304
List *outer_selectivities;
305-
List *current_selectivities;
305+
List *current_selectivities = NULL;
306306

307307
if (use_aqo || learn_aqo)
308308
current_selectivities = get_selectivities(root, restrict_clauses, 0,

machine_learning.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ OkNNr_predict(int matrix_rows, int matrix_cols,
116116
if (idx[i] != -1)
117117
result += targets[idx[i]] * w[i] / w_sum;
118118

119-
pfree(w);
120-
pfree(distances);
119+
if (result < 0)
120+
result = 0;
121121

122122
/* this should never happen */
123123
if (idx[0] == -1)
124-
return -1;
124+
result = -1;
125125

126+
pfree(w);
127+
pfree(distances);
126128
pfree(idx);
127129

128-
if (result < 0)
129-
result = 0;
130130
return result;
131131
}
132132

0 commit comments

Comments
 (0)