home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / sgi / 12443 < prev    next >
Encoding:
Text File  |  1992-08-14  |  2.0 KB  |  74 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!uunet.ca!geac!snitor!sni.ca!ash
  3. From: ash@sni.ca (Ashwin Palekar)
  4. Subject: Possible bug in c-compiler ? 
  5. Message-ID: <1992Aug14.165251.20524@sni.ca>
  6. Sender: ash@iron.sni.ca (Ashwin Palekar)
  7. Nntp-Posting-Host: iron.sni.ca
  8. Organization: Siemens Nixdorf, Sietec Open Systems, Toronto, Canada
  9. Date: Fri, 14 Aug 1992 16:52:51 GMT
  10. Lines: 62
  11.  
  12. ON: IRIX 4.0.1 11150233 IP12
  13.  
  14. Problem Description:
  15. ~~~~~~~~~~~~~~~~~~~~
  16.     The software works with debug version (default compiler option)
  17. and dumps core in optimised version (-O).
  18.  
  19. Problem Analysis :
  20. ~~~~~~~~~~~~~~~~~
  21.     the code has the following logic.
  22. {
  23.     struct xyz *variable=NULL;
  24.     setjmp();
  25.     
  26.     variable = ... allocate memory.
  27.     free (variable)
  28.     variable = NULL; 
  29.  
  30.     longjmp(Go to statement shown next)
  31.  
  32.     if variable != NULL free(variable)
  33.     
  34. }
  35.  
  36. In debug mode "variable" is equal to NULL after longjmp.
  37. In optimised mode "variable" it is not NULL after longjmp tries to free it
  38. resulting in core dump.
  39.  
  40. IMP: This same behaviour is noticed on mips platform (maybe because of 
  41. same compiler).
  42.  
  43. Temporary Solution:
  44. ~~~~~~~~~~~~~~~~~~~
  45.     If I make the variable declaration static it works in both cases.
  46.  
  47. Possible explaination: 
  48. ~~~~~~~~~~~~~~~~~~~~~
  49.  
  50.     setjmp may not store registers , and if during optimization the 
  51. structure is made register variable then it will result in choas.
  52.  
  53. Background:
  54. ~~~~~~~~~~
  55.     The software works on lots of other platforms (with same source code).
  56. I checked for memory leaks before the function starts , none that i could 
  57. find. 
  58.  
  59.  
  60. Other inputs:
  61. ~~~~~~~~~~~~~~~~~~~~~    
  62. The software uses 'setjmp' and 'longjmp' extensively and many cases do work
  63. fine.
  64.  
  65. -- 
  66. ---------------------------------------------------------------------------
  67. Ashwin Palekar : ash@sni.ca
  68. Office:
  69. Tel : (416) 496-8510 
  70. Fax : (416) 496-8524 
  71. Siemens Nixdorf Information Systems Ltd.,
  72. 2235 Sheppard Ave. East, Suite 1800, Willowdale , Ontario , Canada M2J 3B5.
  73. ---------------------------------------------------------------------------
  74.