delete the clones

This commit is contained in:
2026-02-16 03:24:54 -05:00
parent 06ed6a2c97
commit 96896a0f97
2 changed files with 16 additions and 0 deletions

View File

@@ -173,12 +173,14 @@ parse_key_condition_expression :: proc(
eq_token := next_token(&t) or_return eq_token := next_token(&t) or_return
if eq_token != "=" { if eq_token != "=" {
delete(pk_name) // free on error
return return
} }
pk_value_token := next_token(&t) or_return pk_value_token := next_token(&t) or_return
pk_value, pk_ok := resolve_attribute_value(pk_value_token, attribute_values) pk_value, pk_ok := resolve_attribute_value(pk_value_token, attribute_values)
if !pk_ok { if !pk_ok {
delete(pk_name) // free on error
return return
} }
@@ -187,12 +189,14 @@ parse_key_condition_expression :: proc(
// Optional "AND ..." // Optional "AND ..."
if and_token, has_and := tokenizer_next(&t).?; has_and { if and_token, has_and := tokenizer_next(&t).?; has_and {
if !strings.equal_fold(and_token, "AND") { if !strings.equal_fold(and_token, "AND") {
delete(pk_name) // free on error
attr_value_destroy(&pk_value) attr_value_destroy(&pk_value)
return return
} }
skc, skc_ok := parse_sort_key_condition(&t, attribute_names, attribute_values) skc, skc_ok := parse_sort_key_condition(&t, attribute_names, attribute_values)
if !skc_ok { if !skc_ok {
delete(pk_name) // free on error
attr_value_destroy(&pk_value) attr_value_destroy(&pk_value)
return return
} }
@@ -228,12 +232,14 @@ parse_sort_key_condition :: proc(
op_token := next_token(t) or_return op_token := next_token(t) or_return
operator, op_ok := parse_operator(op_token) operator, op_ok := parse_operator(op_token)
if !op_ok { if !op_ok {
delete(sk_name) // free on error
return return
} }
value_token := next_token(t) or_return value_token := next_token(t) or_return
value, val_ok := resolve_attribute_value(value_token, attribute_values) value, val_ok := resolve_attribute_value(value_token, attribute_values)
if !val_ok { if !val_ok {
delete(sk_name) // free on error
return return
} }
@@ -242,18 +248,21 @@ parse_sort_key_condition :: proc(
// IMPORTANT: after allocating `value`, do NOT use `or_return` without cleanup. // IMPORTANT: after allocating `value`, do NOT use `or_return` without cleanup.
and_token, tok_ok := next_token(t) and_token, tok_ok := next_token(t)
if !tok_ok || !strings.equal_fold(and_token, "AND") { if !tok_ok || !strings.equal_fold(and_token, "AND") {
delete(sk_name) // free on error
attr_value_destroy(&value) attr_value_destroy(&value)
return return
} }
value2_token, tok2_ok := next_token(t) value2_token, tok2_ok := next_token(t)
if !tok2_ok { if !tok2_ok {
delete(sk_name) // free on error
attr_value_destroy(&value) attr_value_destroy(&value)
return return
} }
v2, v2_ok := resolve_attribute_value(value2_token, attribute_values) v2, v2_ok := resolve_attribute_value(value2_token, attribute_values)
if !v2_ok { if !v2_ok {
delete(sk_name) // free on error
attr_value_destroy(&value) attr_value_destroy(&value)
return return
} }
@@ -287,18 +296,21 @@ parse_begins_with :: proc(
comma := next_token(t) or_return comma := next_token(t) or_return
if comma != "," { if comma != "," {
delete(sk_name) // free on error
return return
} }
value_token := next_token(t) or_return value_token := next_token(t) or_return
value, val_ok := resolve_attribute_value(value_token, attribute_values) value, val_ok := resolve_attribute_value(value_token, attribute_values)
if !val_ok { if !val_ok {
delete(sk_name) // free on error
return return
} }
// after allocating `value`, avoid `or_return` so we can clean up // after allocating `value`, avoid `or_return` so we can clean up
rparen, tok_ok := next_token(t) rparen, tok_ok := next_token(t)
if !tok_ok || rparen != ")" { if !tok_ok || rparen != ")" {
delete(sk_name) // free on error
attr_value_destroy(&value) attr_value_destroy(&value)
return return
} }

View File

@@ -51,6 +51,10 @@ parse_projection_expression :: proc(
resolved, res_ok := resolve_attribute_name(trimmed, attribute_names) resolved, res_ok := resolve_attribute_name(trimmed, attribute_names)
if !res_ok { if !res_ok {
// Cleanup previously cloned strings
for path in result {
delete(path)
}
delete(result) delete(result)
return nil, false return nil, false
} }