walterzhaoJR commented on PR #3244: URL: https://github.com/apache/brpc/pull/3244#issuecomment-4072717699
> Normally, this kind of problem is handled by adding a dummy element to the linked list during initialization. When there are no elements, the head pointer points to the dummy element. Checking for null is done by checking if `head == dummy->next`. > > Would this implementation be better? Thank you for the suggestion. I agree that using a dummy/sentinel node is a common way to simplify linked-list handling, especially for empty-list and head-update cases. For this bug, my understanding is that the main issue is not only the null-head case, but that the same Block may be returned to the TLS free list more than once, or that the returned chain may overlap with blocks already in the TLS list. In such cases, even with a sentinel node, I think we would still need an explicit check to prevent duplicate/overlapping insertion; otherwise the list could still become cyclic. So I think a sentinel-based implementation could be a reasonable cleanup or refactoring, but I am not sure it would fully address this bug by itself. That is why my current fix focuses first on guarding against duplicate/overlapping returns. I may be missing something here, so if you think the sentinel approach would help make this safer or cleaner overall, I would be happy to learn more and discuss it further. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
