mirror of
				https://github.com/berlin-open-wireless-lab/DAWN.git
				synced 2025-03-09 15:40:12 +00:00 
			
		
		
		
	memory_utils: fix reallocation
Fixes errors in the form of:
  dawn: mem-audit: Releasing memory we hadn't registered (tcpsocket.c:142)...
  dawn: mem-audit: attempted to register memory already registered (M@tcpsocket.c:114)...
Fixes: 850a75c182 ("fix compilation with GCC12")
Signed-off-by: Nick Hainke <vincent@systemli.org>
			
			
This commit is contained in:
		
							parent
							
								
									5d8df44a3a
								
							
						
					
					
						commit
						58861a1adb
					
				
					 1 changed files with 15 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -33,7 +33,21 @@ void* ret = NULL;
 | 
			
		|||
    case DAWN_REALLOC:
 | 
			
		||||
        ret = realloc(ptr, size);
 | 
			
		||||
        if (ret != NULL)
 | 
			
		||||
          dawn_memory_unregister(DAWN_REALLOC, file, line, ret);
 | 
			
		||||
/*
 | 
			
		||||
GCC v12 has a new Wuse-after-free error. We can not unregister 
 | 
			
		||||
the memory before doing a reallocation. The call can fail, so
 | 
			
		||||
ptr is never freed. However, the warning can be ignored, since
 | 
			
		||||
ptr is only used in the unregister function as a reference to
 | 
			
		||||
remove it from our memory auditing.
 | 
			
		||||
*/
 | 
			
		||||
#if (__GNUC__ >= 12)
 | 
			
		||||
#pragma GCC diagnostic push
 | 
			
		||||
#pragma GCC diagnostic ignored "-Wuse-after-free"
 | 
			
		||||
            dawn_memory_unregister(DAWN_REALLOC, file, line, ptr);
 | 
			
		||||
#pragma GCC diagnostic pop
 | 
			
		||||
#else
 | 
			
		||||
            dawn_memory_unregister(DAWN_REALLOC, file, line, ptr);
 | 
			
		||||
#endif
 | 
			
		||||
        break;
 | 
			
		||||
    case DAWN_CALLOC:
 | 
			
		||||
        ret = calloc(nmemb, size);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue