Skip to content

Commit d129246

Browse files
committed
fix(cypher): free complete return-clause state on parse-error paths
The over-cap ORDER BY rejection path (and the two sibling error paths in parse_return_or_with) freed the items array but not the strings inside it - ASan flagged 7 leaked bytes on the diag and Linux legs the moment the new over-cap test exercised the path. Route all three error paths through free_return_clause(), which already releases item strings, CASE expressions, args and the ORDER BY key list. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 0a0ef51 commit d129246

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎src/cypher/cypher.c‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1720,6 +1720,8 @@ static int parse_order_by_clause(parser_t *p, cbm_return_clause_t *r) {
17201720
return 0;
17211721
}
17221722

1723+
static void free_return_clause(cbm_return_clause_t *r);
1724+
17231725
/* Parse RETURN/WITH clause (shared logic) */
17241726
static int parse_return_or_with(parser_t *p, cbm_return_clause_t **out, bool is_with) {
17251727
cbm_token_type_t tok = (int)is_with ? TOK_WITH : TOK_RETURN;
@@ -1753,8 +1755,7 @@ static int parse_return_or_with(parser_t *p, cbm_return_clause_t **out, bool is_
17531755

17541756
cbm_return_item_t item = {0};
17551757
if (parse_return_item(p, &item) < 0) {
1756-
free(r->items);
1757-
free(r);
1758+
free_return_clause(r);
17581759
return CBM_NOT_FOUND;
17591760
}
17601761

@@ -1771,20 +1772,15 @@ static int parse_return_or_with(parser_t *p, cbm_return_clause_t **out, bool is_
17711772
* parsed item count to that width so an over-wide RETURN is rejected here
17721773
* instead of writing past those arrays downstream. */
17731774
if (r->count > CBM_SZ_32) {
1774-
free(r->items);
1775-
free(r);
1775+
free_return_clause(r);
17761776
return CBM_NOT_FOUND;
17771777
}
17781778

17791779
tail:
17801780
/* Optional ORDER BY */
17811781
if (match(p, TOK_ORDER)) {
17821782
if (parse_order_by_clause(p, r) < 0) {
1783-
for (int k = 0; k < r->order_key_count; k++) {
1784-
safe_str_free(&r->order_keys[k]);
1785-
}
1786-
free(r->items);
1787-
free(r);
1783+
free_return_clause(r);
17881784
return CBM_NOT_FOUND;
17891785
}
17901786
}

0 commit comments

Comments
 (0)