Bug 794316: update the 'higher' pointer of the layer right below the new
authorwtc%google.com
Fri, 28 Sep 2012 14:21:22 +0000
changeset 4409 a727bb87d510c371e2303a7b0e4976284e661d60
parent 4408 5c286707aac3618cacc42940eeb10d10199ba212
child 4411 2dcdce0418f053bd263a766aec37b9cd6e7cf9f6
push idunknown
push userunknown
push dateunknown
bugs794316
Bug 794316: update the 'higher' pointer of the layer right below the new top of the stack after the old top is popped. r=michal.novotny. Modified Files: pr/src/io/prlayer.c pr/tests/pushtop.c
pr/src/io/prlayer.c
pr/tests/pushtop.c
--- a/pr/src/io/prlayer.c
+++ b/pr/src/io/prlayer.c
@@ -561,16 +561,20 @@ PR_IMPLEMENT(PRFileDesc*) PR_PopIOLayer(
     if (extract == stack) {
         /* popping top layer of the stack */
 		/* old style stack */
         PRFileDesc copy = *stack;
         extract = stack->lower;
         *stack = *extract;
         *extract = copy;
         stack->higher = NULL;
+        if (stack->lower) {
+            PR_ASSERT(stack->lower->higher == extract);
+            stack->lower->higher = stack;
+        }
 	} else if ((PR_IO_LAYER_HEAD == stack->identity) &&
 					(extract == stack->lower) && (extract->lower == NULL)) {
 			/*
 			 * new style stack
 			 * popping the only layer in the stack; delete the stack too
 			 */
 			stack->lower = NULL;
 			_PR_DestroyIOLayer(stack);
--- a/pr/tests/pushtop.c
+++ b/pr/tests/pushtop.c
@@ -43,16 +43,27 @@ int main()
     if (bottom->higher != middle) {
         fprintf(stderr, "bottom->higher is wrong\n");
         fprintf(stderr, "FAILED\n");
         exit(1);
     }
 
     top = PR_PopIOLayer(fd, topId);
     top->dtor(top);
+
+    middle = fd;
+    bottom = middle->lower;
+
+    /* Verify that the higher pointer is correct. */
+    if (bottom->higher != middle) {
+        fprintf(stderr, "bottom->higher is wrong\n");
+        fprintf(stderr, "FAILED\n");
+        exit(1);
+    }
+
     middle = PR_PopIOLayer(fd, middleId);
     middle->dtor(middle);
     if (fd->identity != bottomId) {
         fprintf(stderr, "The bottom layer has the wrong identity\n");
         fprintf(stderr, "FAILED\n");
         exit(1);
     }
     fd->dtor(fd);