Copilot commented on code in PR #13876:
URL: https://github.com/apache/trafficserver/pull/13876#discussion_r4334751740


##########
src/iocore/cache/CacheWrite.cc:
##########
@@ -794,8 +794,8 @@ CacheVC::openWriteStartBegin(int /* event ATS_UNUSED */, 
Event * /* e ATS_UNUSED
   if (((err = stripe->open_write_lock(this, false, 1)) > 0)) {
     ts::Metrics::Counter::increment(cache_rsb.status[op_type].failure);
     
ts::Metrics::Counter::increment(stripe->cache_vol->vol_rsb.status[op_type].failure);
-    free_CacheVC(this);
     _action.continuation->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, 
reinterpret_cast<void *>(-err));
+    free_CacheVC(this);
     return EVENT_DONE;

Review Comment:
   Calling the continuation before freeing `this` fixes the UAF, but it can 
introduce a double-free risk if the continuation (which commonly holds the 
`Action*`/VC pointer from the original `open_write` call) closes/frees the 
`CacheVC` during `handleEvent`. After `handleEvent` returns, 
`free_CacheVC(this)` may then free an already-freed VC. Consider using a 
pattern that avoids touching or freeing `this` after invoking the callback 
(e.g., transfer ownership so the callback path is responsible for cleanup, or 
make `free_CacheVC` conditional/idempotent for this failure path, or defer 
cleanup via scheduling so the callback can't synchronously destroy the same 
object twice).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to