volser-newtrans-racy-20081012
authorJeffrey Hutzelman <jhutz@cmu.edu>
Sun, 12 Oct 2008 18:53:06 +0000 (18:53 +0000)
committerDerrick Brashear <shadow@dementia.org>
Sun, 12 Oct 2008 18:53:06 +0000 (18:53 +0000)
LICENSE IPL10
FIXES 121263

avoid a race on creating new transactions in volserver

src/volser/voltrans.c

index df5f20f..610e75b 100644 (file)
@@ -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;