Skip to content

Commit 2ef57b6

Browse files
committed
Ensure memset does not get optimized away
1 parent aef715d commit 2ef57b6

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

ext-src/swoole_coroutine.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,16 +645,21 @@ void PHPCoroutine::on_resume(void *arg) {
645645
swoole_trace_log(SW_TRACE_COROUTINE, "from cid=%ld to cid=%ld", Coroutine::get_current_cid(), ctx->co->get_cid());
646646
}
647647

648+
#pragma GCC push_options
649+
#pragma GCC optimize("O0")
648650
void PHPCoroutine::on_close(void *arg) {
649651
PHPContext *ctx = (PHPContext *) arg;
650652
if (ctx->on_close) {
651653
(*ctx->on_close)(ctx);
652654
}
653-
654655
// Mark memory region with special byte pattern to detect use-after-free
655-
memset(ctx, 0xAA, sizeof(PHPContext));
656+
// std::memset_explicit(ctx, 0xAA, sizeof(PHPContext));
657+
volatile char* ctx_ptr = reinterpret_cast<volatile char *>(ctx);
658+
memset((void*)ctx_ptr, 0xAA, sizeof(PHPContext));
659+
656660
efree(ctx);
657661
}
662+
#pragma GCC pop_options
658663

659664
void PHPCoroutine::destroy_context(PHPContext *ctx) {
660665
PHPContext *origin_ctx = get_origin_context(ctx);

0 commit comments

Comments
 (0)