Add check in RefObject::decr(); Fix decr() in removeAt see https://github.com/Microsoft/pxt/issues/3093 (#544)
This commit is contained in:
		
				
					committed by
					
						
						Peli de Halleux
					
				
			
			
				
	
			
			
			
						parent
						
							faae856e88
						
					
				
				
					commit
					9382535d29
				
			@@ -394,10 +394,7 @@ namespace pxt {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    uint32_t RefCollection::removeAt(int i)
 | 
					    uint32_t RefCollection::removeAt(int i)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      if (isRef())
 | 
					      // no decr() - we return the result
 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        decr(head.get(i));
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      return head.remove(i);
 | 
					      return head.remove(i);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -464,7 +461,8 @@ namespace pxt {
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
      int idx = indexOf(x, 0);
 | 
					      int idx = indexOf(x, 0);
 | 
				
			||||||
      if (idx >= 0) {
 | 
					      if (idx >= 0) {
 | 
				
			||||||
        removeAt(idx);
 | 
					        uint32_t elt = removeAt(idx);
 | 
				
			||||||
 | 
					        if (isRef()) decr(elt);
 | 
				
			||||||
        return 1;
 | 
					        return 1;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      return 0;
 | 
					      return 0;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -160,6 +160,7 @@ namespace pxt {
 | 
				
			|||||||
    inline void unref()
 | 
					    inline void unref()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      //printf("DECR "); this->print();
 | 
					      //printf("DECR "); this->print();
 | 
				
			||||||
 | 
					      check(refcnt > 0, ERR_REF_DELETED);
 | 
				
			||||||
      refcnt -= 2;
 | 
					      refcnt -= 2;
 | 
				
			||||||
      if (refcnt == 0) {
 | 
					      if (refcnt == 0) {
 | 
				
			||||||
        destroy();
 | 
					        destroy();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user