From 322f7e0e9fff02c5d6cad8d9aded3e40abce93ef Mon Sep 17 00:00:00 2001 From: Jeffrey Hutzelman Date: Sun, 12 Oct 2008 18:53:06 +0000 Subject: [PATCH] volser-newtrans-racy-20081012 LICENSE IPL10 FIXES 121263 avoid a race on creating new transactions in volserver --- src/volser/voltrans.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/volser/voltrans.c b/src/volser/voltrans.c index df5f20f..610e75b 100644 --- a/src/volser/voltrans.c +++ b/src/volser/voltrans.c @@ -74,20 +74,21 @@ struct volser_trans * NewTrans(afs_int32 avol, afs_int32 apart) { /* set volid, next, partition */ - register struct volser_trans *tt; + struct volser_trans *tt, *newtt; struct timeval tp; struct timezone tzp; + newtt = (struct volser_trans *)malloc(sizeof(struct volser_trans)); VTRANS_LOCK; /* don't allow the same volume to be attached twice */ for (tt = allTrans; tt; tt = tt->next) { if ((tt->volid == avol) && (tt->partition == apart)) { VTRANS_UNLOCK; + free(newtt); return (struct volser_trans *)0; /* volume busy */ } } - VTRANS_UNLOCK; - tt = (struct volser_trans *)malloc(sizeof(struct volser_trans)); + newtt = tt; memset(tt, 0, sizeof(struct volser_trans)); tt->volid = avol; tt->partition = apart; @@ -97,7 +98,6 @@ NewTrans(afs_int32 avol, afs_int32 apart) gettimeofday(&tp, &tzp); tt->creationTime = tp.tv_sec; tt->time = FT_ApproxTime(); - VTRANS_LOCK; tt->tid = transCounter++; tt->next = allTrans; allTrans = tt; -- 1.9.4