home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lclint.zip / lclint-2_3h-os2-bin.zip / test / sharing3.c < prev    next >
C/C++ Source or Header  |  1997-09-03  |  866b  |  62 lines

  1. extern /*@only@*/ char *string_copyext (char *s) ;
  2.  
  3. void f (void)
  4. {
  5.   char *s;
  6.  
  7.   if (3 < 4)
  8.     {
  9.       s = string_copyext ("asdf");
  10.       free (s);
  11.     }
  12. }
  13.  
  14.  
  15. /*@only@*/ char *string_copy (char *s) 
  16.   return s; /* 1. returns temp as only! */
  17. }
  18.  
  19. /*@only@*/ char *copy_string1 (char *s)
  20. {
  21.   return string_copy (s); /* okay */
  22. }
  23.  
  24. /*@only@*/ char *copy_string2 (char *s)
  25. {
  26.   return string_copyext (s); /* okay */
  27. }
  28.  
  29. void string_free1 (char *s)
  30. {
  31.   free (s); /* 2. unqualified as only */
  32. }
  33.  
  34. void string_free2 (/*@only@*/ char *s)
  35. {
  36.   free (s);
  37. }
  38.  
  39. void string_free3 (/*@only@*/ char *s)
  40. {
  41.   char *t = string_copy (s);
  42.   string_free2 (s);
  43.   *t = 'a';
  44. } /* 3. bad, t not released */
  45.  
  46. void string_free4 (/*@only@*/ char *s)
  47. {
  48.   char *t;
  49.   int i;
  50.  
  51.   for (i = 0; i < 3; i++)
  52.     {
  53.       t = string_copy (s);
  54.       *t = 'a';
  55.       free (t);
  56.     }
  57.  
  58.   free (s);
  59. } /* okay */
  60.  
  61.