gongxun0928 commented on code in PR #1322: URL: https://github.com/apache/cloudberry/pull/1322#discussion_r2290495124
########## src/backend/commands/resgroupcmds.c: ########## @@ -1093,11 +1093,26 @@ alterResgroupCallback(XactEvent event, void *arg) if (event == XACT_EVENT_COMMIT) ResGroupAlterOnCommit(callbackCtx); + /* + * Free io_limit resources allocated in AlterResourceGroup(). + * + * We need to handle two cases: + * 1. caps.io_limit != oldCaps.io_limit: case RESGROUP_LIMIT_TYPE_IO_LIMIT + * 2. caps.io_limit == oldCaps.io_limit: other cases + * + * The pointer comparison (oldCaps.io_limit != caps.io_limit) is crucial to + * avoid double free errors. When "other cases", both pointers might + * reference the same memory location, so we only free oldCaps.io_limit if + * it's different from caps.io_limit. + */ if (callbackCtx->caps.io_limit != NIL) + { cgroupOpsRoutine->freeio(callbackCtx->caps.io_limit); - if (callbackCtx->caps.io_limit != NIL) - cgroupOpsRoutine->freeio(callbackCtx->oldCaps.io_limit); + if (callbackCtx->oldCaps.io_limit != NIL && Review Comment: when `callbackCtx->caps.io_limit == NULL && callbackCtx->oldCaps.io_limit != NULL` , callbackCtx->oldCaps.io_limit will be leaked -- 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: commits-unsubscr...@cloudberry.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org For additional commands, e-mail: commits-h...@cloudberry.apache.org