View Single Post
Old Nov 8th, 2006, 1:00 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Right away you are setting envVar to an address of memory loaned to you by malloc. Right after that you are setting it to an address given to you by 'getenv'. You have lost the address given to you by malloc, thus you will not be able to free it without barfing in your own shirt pocket. I would suggest that you learn, first, about pointers, and secondly, about malloc/free and its requirements. Actually, since this is C++, you should shelve malloc/free in favor of new/delete.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote