PengZheng commented on code in PR #780:
URL: https://github.com/apache/celix/pull/780#discussion_r1911968571
##########
libs/framework/src/framework.c:
##########
@@ -2663,38 +2667,43 @@ long celix_framework_nextScheduledEventId(framework_t
*fw) {
return __atomic_fetch_add(&fw->dispatcher.nextScheduledEventId, 1,
__ATOMIC_RELAXED);
}
-/**
- * @brief Checks if a generic event with the provided eventId is in progress.
- */
-static bool celix_framework_isGenericEventInProgress(celix_framework_t* fw,
long eventId) {
- // precondition fw->dispatcher.mutex locked)
+static celix_framework_event_t*
celix_framework_getGenericEvent(celix_framework_t* fw, long eventId) {
+ // precondition fw->dispatcher.mutex locked
for (int i = 0; i < fw->dispatcher.eventQueueSize; ++i) {
int index = (fw->dispatcher.eventQueueFirstEntry + i) %
fw->dispatcher.eventQueueCap;
celix_framework_event_t* e = &fw->dispatcher.eventQueue[index];
if (e->type == CELIX_GENERIC_EVENT && e->genericEventId == eventId) {
- return true;;
+ return e;
}
}
for (int i = 0; i <
celix_arrayList_size(fw->dispatcher.dynamicEventQueue); ++i) {
celix_framework_event_t* e =
celix_arrayList_get(fw->dispatcher.dynamicEventQueue, i);
if (e->type == CELIX_GENERIC_EVENT && e->genericEventId == eventId) {
- return true;
+ return e;
}
}
- return false;
+ return NULL;
}
void celix_framework_waitForGenericEvent(celix_framework_t* fw, long eventId) {
assert(!celix_framework_isCurrentThreadTheEventLoop(fw));
- struct timespec logAbsTime = celixThreadCondition_getDelayedTime(5);
+ struct timespec logAbsTime =
celixThreadCondition_getDelayedTime(fw->dispatcher.genericEventTimeoutInSeconds);
celixThreadMutex_lock(&fw->dispatcher.mutex);
- while (celix_framework_isGenericEventInProgress(fw, eventId)) {
+ celix_framework_event_t* event = celix_framework_getGenericEvent(fw,
eventId);
+ while (event) {
celix_status_t waitStatus =
celixThreadCondition_waitUntil(&fw->dispatcher.cond,
&fw->dispatcher.mutex, &logAbsTime);
if (waitStatus == ETIMEDOUT) {
- fw_log(fw->logger, CELIX_LOG_LEVEL_WARNING, "Generic event with id
%li not finished.", eventId);
- logAbsTime = celixThreadCondition_getDelayedTime(5);
- }
+ fw_log(fw->logger,
Review Comment:
Potential use-after-free. `dispatcher.mutex` is release when waiting for
`dispatcher.cond`, and thus `event` could be removed. The intention is good but
we can not really do this.
--
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]