[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/dlm/tests/usertest flood.c



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	pcaulfield sourceware org	2007-03-27 16:02:42

Modified files:
	dlm/tests/usertest: flood.c 

Log message:
	Fix bug where we could free an lksb while dlm_lock is still using it.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/dlm/tests/usertest/flood.c.diff?cvsroot=cluster&r1=1.2&r2=1.3

--- cluster/dlm/tests/usertest/flood.c	2007/01/09 14:17:37	1.2
+++ cluster/dlm/tests/usertest/flood.c	2007/03/27 15:02:42	1.3
@@ -55,9 +55,7 @@
 
     if (lksb->sb_status == EUNLOCK) {
 	    count--;
-	    free(lksb);
     }
-
 }
 
 int main(int argc, char *argv[])
@@ -71,8 +69,10 @@
     int  status;
     int  i;
     int  mode = LKM_CRMODE;
+    int  lksbnum = 0;
     signed char opt;
     char **resources;
+    struct dlm_lksb *lksbs;
 
     /* Deal with command-line arguments */
     opterr = 0;
@@ -106,7 +106,7 @@
 	    break;
 
 	case 'V':
-	    printf("\nflood version 0.2\n\n");
+	    printf("\nflood version 0.3\n\n");
 	    exit(1);
 	    break;
 	}
@@ -119,6 +119,13 @@
 	    resources[i] = strdup(resname);
     }
 
+    lksbs = malloc(sizeof(struct dlm_lksb) * maxlocks);
+    if (!lksbs)
+    {
+	    perror("cannot allocate lksbs");
+	    return 1;
+    }
+
     pthread_cond_init(&cond, NULL);
     pthread_mutex_init(&mutex, NULL);
     pthread_mutex_lock(&mutex);
@@ -127,18 +134,15 @@
 
     while (1) {
 	    char *resource = resources[rand() % rescount];
-	    struct dlm_lksb *lksb = malloc(sizeof(struct dlm_lksb));
-	    if (!lksb)
-		    exit(1);
 
 	    status = dlm_lock(mode,
-			      lksb,
+			      &lksbs[lksbnum],
 			      flags,
 			      resource,
 			      strlen(resource),
 			      0, // Parent,
 			      ast_routine,
-			      lksb,
+			      &lksbs[lksbnum],
 			      NULL, // bast_routine,
 			      NULL); // Range
 	    if (status == -1)
@@ -155,7 +159,7 @@
 	    while (count > maxlocks) {
 		    sleep(1);
 	    }
-
+	    lksbnum = (lksbnum+1)%maxlocks;
     }
 
     return 0;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]