Skip to content

Commit 8b68a94

Browse files
committed
Mirror coverity fixes for subscription locking code.
1 parent 81d7ca3 commit 8b68a94

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

scheduler/ipp.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,12 +3624,17 @@ static int /* O - 1 if OK, 0 if not */
36243624
check_rss_recipient(
36253625
const char *recipient) /* I - Recipient URI */
36263626
{
3627+
int i, /* Looping var */
3628+
scount; /* Number of subscriptions */
36273629
cupsd_subscription_t *sub; /* Current subscription */
36283630

36293631

3630-
for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
3631-
sub;
3632-
sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
3632+
_cupsRWLockRead(&SubscriptionsLock);
3633+
3634+
for (i = 0, scount = cupsArrayCount(Subscriptions); i < scount; i ++)
3635+
{
3636+
sub = (cupsd_subscription_t *)cupsArrayIndex(Subscriptions, i);
3637+
36333638
if (sub->recipient)
36343639
{
36353640
/*
@@ -3645,6 +3650,9 @@ check_rss_recipient(
36453650
if (*r1 == *r2)
36463651
return (0);
36473652
}
3653+
}
3654+
3655+
_cupsRWUnlock(&SubscriptionsLock);
36483656

36493657
return (1);
36503658
}
@@ -9509,14 +9517,14 @@ renew_subscription(
95099517

95109518
sub->expire = sub->lease ? time(NULL) + sub->lease : 0;
95119519

9512-
_cupsRWUnlock(&sub->lock);
9513-
95149520
cupsdMarkDirty(CUPSD_DIRTY_SUBSCRIPTIONS);
95159521

95169522
con->response->request.status.status_code = IPP_STATUS_OK;
95179523

95189524
ippAddInteger(con->response, IPP_TAG_SUBSCRIPTION, IPP_TAG_INTEGER,
95199525
"notify-lease-duration", sub->lease);
9526+
9527+
_cupsRWUnlock(&sub->lock);
95209528
}
95219529

95229530

scheduler/subscriptions.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,23 @@ cupsdDeleteAllSubscriptions(void)
418418
cupsd_subscription_t *sub; /* Subscription */
419419

420420

421-
if (!Subscriptions)
422-
return;
423-
424421
_cupsRWLockWrite(&SubscriptionsLock);
425422

423+
if (!Subscriptions)
424+
goto done;
425+
426426
for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
427427
sub;
428428
sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
429+
{
429430
cupsdDeleteSubscription(sub, -1);
431+
}
430432

431433
cupsArrayDelete(Subscriptions);
432434
Subscriptions = NULL;
433435

436+
done:
437+
434438
_cupsRWUnlock(&SubscriptionsLock);
435439
}
436440

@@ -641,20 +645,19 @@ cupsdExpireSubscriptions(
641645
cupsd_job_t *job) /* I - Job, if any */
642646
{
643647
cupsd_subscription_t *sub; /* Current subscription */
644-
int update; /* Update subscriptions.conf? */
648+
int update = 0; /* Update subscriptions.conf? */
645649
time_t curtime; /* Current time */
646650

647651

652+
_cupsRWLockWrite(&SubscriptionsLock);
653+
648654
if (cupsArrayCount(Subscriptions) == 0)
649-
return;
655+
goto done;
650656

651657
curtime = time(NULL);
652-
update = 0;
653658

654659
cupsdLogMessage(CUPSD_LOG_DEBUG, "Expiring subscriptions...");
655660

656-
_cupsRWLockWrite(&SubscriptionsLock);
657-
658661
for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
659662
sub;
660663
sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
@@ -672,6 +675,8 @@ cupsdExpireSubscriptions(
672675
}
673676
}
674677

678+
done:
679+
675680
_cupsRWUnlock(&SubscriptionsLock);
676681

677682
if (update)
@@ -1206,16 +1211,22 @@ cupsdStopAllNotifiers(void)
12061211
* Yes, kill any processes that are left...
12071212
*/
12081213

1214+
_cupsRWLockWrite(&SubscriptionsLock);
1215+
12091216
for (sub = (cupsd_subscription_t *)cupsArrayFirst(Subscriptions);
12101217
sub;
12111218
sub = (cupsd_subscription_t *)cupsArrayNext(Subscriptions))
1219+
{
12121220
if (sub->pid)
12131221
{
12141222
cupsdEndProcess(sub->pid, 0);
12151223

12161224
close(sub->pipe);
12171225
sub->pipe = -1;
12181226
}
1227+
}
1228+
1229+
_cupsRWUnlock(&SubscriptionsLock);
12191230

12201231
/*
12211232
* Close the status pipes...
@@ -1386,7 +1397,7 @@ cupsd_send_notification(
13861397
cupsdLogMessage(CUPSD_LOG_CRIT,
13871398
"Unable to allocate memory for subscription #%d!",
13881399
sub->id);
1389-
return;
1400+
goto done;
13901401
}
13911402
}
13921403

@@ -1474,6 +1485,8 @@ cupsd_send_notification(
14741485

14751486
sub->next_event_id ++;
14761487

1488+
done:
1489+
14771490
_cupsRWUnlock(&sub->lock);
14781491
}
14791492

0 commit comments

Comments
 (0)