- 
                Notifications
    You must be signed in to change notification settings 
- Fork 84
          Improve multi-threaded valid-memcleanup
          #1246
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
            sim642
  merged 23 commits into
  goblint:master
from
mrstanb:improve-multi-threaded-valid-memcleanup
  
      
      
   
  Nov 24, 2023 
      
    
  
     Merged
                    Changes from 18 commits
      Commits
    
    
            Show all changes
          
          
            23 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f209afd
              
                First attempt to improve precision for multi-threaded valid-memcleanup
              
              
                mrstanb c0fe89e
              
                Add regr. test cases for multi-threaded valid-memcleanup
              
              
                mrstanb 7289ec3
              
                Use solely local state for multi-threaded valid-memcleanup
              
              
                mrstanb 720cfee
              
                IsMallocCalled should be `may`
              
              
                michael-schwarz af9ddc7
              
                Add unsound example
              
              
                michael-schwarz 0655fd6
              
                Merge branch 'master' into improve-multi-threaded-valid-memcleanup
              
              
                michael-schwarz ada8491
              
                Make sound by accounting for alloc in global invariant
              
              
                michael-schwarz e7d6302
              
                Cleanup
              
              
                michael-schwarz e6cee27
              
                Fix `memtrack` for multi-threaded case
              
              
                michael-schwarz 97eb715
              
                Account for failing assertions in the multi-threaded case as well
              
              
                mrstanb 987795e
              
                Add a few more test cases
              
              
                mrstanb 8d55024
              
                Add options to produce warnings only for memory leaks
              
              
                mrstanb ca61360
              
                Add example where better privatization helps
              
              
                michael-schwarz 2cc915f
              
                Check at end of main thread that the program is certainly single-thre…
              
              
                jerhard 45ec8a6
              
                Add test case for memory leaking from a thead that is not joined, add…
              
              
                jerhard 56c4d62
              
                Add test case with pthread_exit called in main, remove threadid analy…
              
              
                jerhard 2fef812
              
                Add testcases for thread return and pthread_exit in thread different …
              
              
                jerhard 645b03c
              
                ThreadAnalysis: Handle pthread_exit like return from thread.
              
              
                jerhard c6cb63e
              
                Update tests/regression/76-memleak/16-no-mem-leak-thread-exit-main.c
              
              
                jerhard f12a392
              
                Remove call to free.
              
              
                jerhard be9171b
              
                Add annotation of nowarn next to pthread_exit.
              
              
                jerhard 585a65d
              
                Check in TheadAnalysis.return whether the return is actually a thread…
              
              
                jerhard bc7694b
              
                Add test case that checking that analysis distinguishes between threa…
              
              
                jerhard File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            37 changes: 37 additions & 0 deletions
          
          37 
        
  tests/regression/76-memleak/08-invalid-memcleanup-multi-threaded.c
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread | ||
| #include <stdlib.h> | ||
| #include <pthread.h> | ||
|  | ||
| int *g; | ||
| int *m1; | ||
|  | ||
| void *f1(void *arg) { | ||
| m1 = malloc(sizeof(int)); | ||
| free(m1); | ||
| // Thread t1 leaks m1 here | ||
| pthread_exit(NULL); //WARN | ||
| } | ||
|  | ||
| void *f2(void *arg) { | ||
| int *m2; | ||
| m2 = malloc(sizeof(int)); | ||
| free(m2); // No leak for thread t2, since it calls free before exiting | ||
| pthread_exit(NULL); //NOWARN | ||
| } | ||
|  | ||
| int main(int argc, char const *argv[]) { | ||
| g = malloc(sizeof(int)); | ||
| pthread_t t1; | ||
| pthread_create(&t1, NULL, f1, NULL); | ||
|  | ||
| pthread_t t2; | ||
| pthread_create(&t2, NULL, f2, NULL); | ||
|  | ||
| free(g); | ||
|  | ||
| pthread_join(t1, NULL); | ||
| pthread_join(t2, NULL); | ||
|  | ||
| // main thread is not leaking anything | ||
| return 0; //NOWARN | ||
| } | 
        
          
          
            35 changes: 35 additions & 0 deletions
          
          35 
        
  tests/regression/76-memleak/09-invalid-memcleanup-multi-threaded-abort.c
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --set ana.activated[+] thread | ||
| #include <pthread.h> | ||
|  | ||
| int *g; | ||
| int *m1; | ||
|  | ||
| void *f1(void *arg) { | ||
| m1 = malloc(sizeof(int)); | ||
| // Thread t1 leaks m1 here | ||
| exit(2); //WARN | ||
| } | ||
|  | ||
| void *f2(void *arg) { | ||
| int *m2; | ||
| m2 = malloc(sizeof(int)); | ||
| free(m2); // No leak for thread t2, since it calls free before exiting | ||
| pthread_exit(NULL); //NOWARN | ||
| } | ||
|  | ||
| int main(int argc, char const *argv[]) { | ||
| g = malloc(sizeof(int)); | ||
| pthread_t t1; | ||
| pthread_create(&t1, NULL, f1, NULL); | ||
|  | ||
| pthread_t t2; | ||
| pthread_create(&t2, NULL, f2, NULL); | ||
|  | ||
| free(g); | ||
|  | ||
| pthread_join(t1, NULL); | ||
| pthread_join(t2, NULL); | ||
|  | ||
| // main thread is not leaking anything | ||
| return 0; //NOWARN | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| //PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
| #include <stdlib.h> | ||
| #include <pthread.h> | ||
|  | ||
| int *g; | ||
| int *m1; | ||
| int *m2; | ||
|  | ||
| void *f1(void *arg) { | ||
| int top; | ||
|  | ||
| // Thread t1 leaks m0 here | ||
| exit(2); //WARN | ||
| } | ||
|  | ||
| int main(int argc, char const *argv[]) { | ||
| pthread_t t1; | ||
| pthread_create(&t1, NULL, f1, NULL); | ||
|  | ||
| int* m0 = malloc(sizeof(int)); | ||
| free(m0); | ||
|  | ||
| // main thread is not leaking anything | ||
| return 0; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak | ||
| #include <stdlib.h> | ||
| #include <pthread.h> | ||
|  | ||
| int *g; | ||
| int *m1; | ||
| int *m2; | ||
|  | ||
| void *f2(void *arg) { | ||
| // Thread t2 leaks m0 and t1_ptr here | ||
| quick_exit(2); //WARN | ||
| } | ||
|  | ||
| void *f1(void *arg) { | ||
| pthread_t t2; | ||
| pthread_create(&t2, NULL, f2, NULL); | ||
|  | ||
| int *t1_ptr = malloc(sizeof(int)); | ||
|  | ||
| pthread_join(t2, NULL); | ||
| // t1_ptr is leaked, since t2 calls quick_exit() potentially before this program point | ||
| free(t1_ptr); | ||
| } | ||
|  | ||
| int main(int argc, char const *argv[]) { | ||
| pthread_t t1; | ||
| pthread_create(&t1, NULL, f1, NULL); | ||
|  | ||
| int* m0 = malloc(sizeof(int)); | ||
| free(m0); | ||
|  | ||
| // main thread is not leaking anything | ||
| return 0; | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| //PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --disable warn.assert | ||
| #include <stdlib.h> | ||
| #include <pthread.h> | ||
| #include <assert.h> | ||
|  | ||
| int *g; | ||
| int *m1; | ||
| int *m2; | ||
|  | ||
| void *f2(void *arg) { | ||
| // Thread t2 leaks m0 and t1_ptr here | ||
| assert(0); //WARN | ||
| } | ||
|  | ||
| void *f1(void *arg) { | ||
| pthread_t t2; | ||
| pthread_create(&t2, NULL, f2, NULL); | ||
|  | ||
| int *t1_ptr = malloc(sizeof(int)); | ||
| assert(1); //NOWARN | ||
| pthread_join(t2, NULL); | ||
| free(t1_ptr); | ||
| } | ||
|  | ||
| int main(int argc, char const *argv[]) { | ||
| pthread_t t1; | ||
| pthread_create(&t1, NULL, f1, NULL); | ||
|  | ||
| int* m0 = malloc(sizeof(int)); | ||
| free(m0); | ||
|  | ||
| // main thread is not leaking anything | ||
| return 0; | ||
| } | 
        
          
          
            20 changes: 20 additions & 0 deletions
          
          20 
        
  tests/regression/76-memleak/13-assert-unknown-multi-threaded.c
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| //PARAM: --set ana.malloc.unique_address_count 1 --set ana.activated[+] memLeak --disable warn.assert | ||
| #include <stdlib.h> | ||
| #include <pthread.h> | ||
| #include <assert.h> | ||
|  | ||
| void *f1(void *arg) { | ||
| int top; | ||
| assert(top); //WARN | ||
| } | ||
|  | ||
| int main(int argc, char const *argv[]) { | ||
| pthread_t t1; | ||
| pthread_create(&t1, NULL, f1, NULL); | ||
|  | ||
| int* m0 = malloc(sizeof(int)); | ||
| free(m0); | ||
|  | ||
| // main thread is not leaking anything | ||
| return 0; | ||
| } | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.