Commits

Anonymous committed d86ce04 Draft

missing a null check upon entry to dereference

  • Participants
  • Parent commits 41f09e1

Comments (0)

Files changed (1)

   pq *next;
   int i;
 
-  printf("pq_alloc\n");
-
  sync_alloc:
-  printf("sync_alloc\n");
-
-  printf("current_pyamt_image : %p\n", current_pyamt_image);
-
-  printf("%p biot90ch\n", current_pyamt_image->roots);
-
-  //oldroot = __sync_synchronize(current_pyamt_image->pq_free);
-  oldroot = current_pyamt_image->pq_free;
-
-  printf("old root is %p. sync image\n", oldroot);
-
+  oldroot = __sync_fetch_and_add(&current_pyamt_image->pq_free, 0);
   sync_pyamt_image();
-
-  printf("ok.\n");
-
   allocated = unmarshal_fn(oldroot);
- 
 
   if (!allocated)
     goto sync_alloc_nodes;
   } goto sync_alloc;
 
  sync_alloc_nodes:
-  printf("sync_alloc_nodes\n");
-
   new = marshal_fn(allocator(sizeof(pq) * SLAB_SIZE));
-
-  printf("new: %p\n", new);
-
   sync_pyamt_image();
-  
-  printf("post sync:\n");
-
   init = unmarshal_fn(new);
   i = 0;
-
-  printf("new %p unmarshals to init %p\n", new, init);
   
   while (i < SLAB_SIZE - 1) {
     next = (void *) init + sizeof(pq);
     ++i;
   }
 
-  printf("initialized slab.\n");
-
   while (1) {
     oldroot = current_pyamt_image->pq_free;
     init->right = oldroot;
       break;
   }
 
-  printf("sync_alloc_nodes ok.\n");
-
   goto sync_alloc;
 }
 
 }
 
 void dereference(pq *x) {
+  if (!x) return;
+
   pq *n = PQ_NODE(x);
 
   if (__sync_sub_and_fetch(&n->refcount, 1))
 
   /* assumption: time_t is expressed in seconds */
   while (now+1 >= z->expiration) {
+
+    printf("now+1: %d\n", now+1);
+    printf("z->exp: %d\n", z->expiration);
+
+
     printf("before constructing new and old\n");
 
     pq *old_root = current_pyamt_image->roots;
     printf("the current image has a root of: %p\n", current_pyamt_image->roots);
     
     if (__sync_bool_compare_and_swap(&current_pyamt_image->roots, old_root, new_root)) {
+
+      printf("about to enter the throes of victory, old boy\n");
+
       z->valid_root = PQ_NODE(new_root)->root;
       z->expiration = PQ_NODE(new_root)->expiry;
+
+      printf("blast and devilment\n");
+
       dereference(old_root); /* victory */
     } else
       dereference(new_root);