Skip to content

Commit 184806f

Browse files
committed
PROTON-1442: Some bugs found by Cursor Review Agent
A potential null pointer access, and a memory leak on error condition
1 parent 73a3eac commit 184806f

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

cpp/src/messaging_adapter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ void handle_transaction_coordinator_outcome(messaging_handler& handler, tracker
137137
case transaction_context::State::DISCHARGING:
138138
// Don't throw error here, instead close link with error
139139
make_wrapper(transaction_context->coordinator).close(error_condition{"amqp:not-allowed", "Received transaction declared disposition in invalid state"});
140-
transaction_context.release();
140+
transaction_context.reset();
141141
}
142142
} else if (pn_disposition_type(disposition) == PN_ACCEPTED) {
143143
switch (state) {
@@ -159,7 +159,7 @@ void handle_transaction_coordinator_outcome(messaging_handler& handler, tracker
159159
case transaction_context::State::DECLARED:
160160
// TODO: Don't throw error here, instead detach link or close session?
161161
make_wrapper(transaction_context->coordinator).close(error_condition{"amqp:not-allowed", "Received transaction accepted disposition in invalid state"});
162-
transaction_context.release();
162+
transaction_context.reset();
163163
}
164164
} else if (auto rejected_disp = pn_rejected_disposition(disposition); rejected_disp) {
165165
switch (state) {
@@ -181,7 +181,7 @@ void handle_transaction_coordinator_outcome(messaging_handler& handler, tracker
181181
case transaction_context::State::DECLARED:
182182
// TODO: Don't throw error here, instead detach link or close session?
183183
make_wrapper(transaction_context->coordinator).close(error_condition{"amqp:not-allowed", "Received transaction rejected disposition in invalid state"});
184-
transaction_context.release();
184+
transaction_context.reset();
185185
}
186186
}
187187
// TODO: Don't ignore unexpected disposition here, instead detach link or close session?

cpp/src/session.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ proton::tracker transaction_send_ctrl(sender&& coordinator, const symbol& descri
183183

184184
void transaction_discharge(const session& s, bool failed) {
185185
auto& transaction_context = get_transaction_context(s);
186-
if (transaction_context->state != transaction_context::State::DECLARED)
186+
if (transaction_is_empty(s) || transaction_context->state != transaction_context::State::DECLARED)
187187
throw proton::error("Only a declared txn can be discharged.");
188188
transaction_context->state = transaction_context::State::DISCHARGING;
189189

0 commit comments

Comments
 (0)