Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!taumet!steve From: steve@taumet.COM (Stephen Clamage) Newsgroups: comp.lang.c Subject: Re: free (NULL) Message-ID: <224@taumet.COM> Date: 29 May 90 15:58:02 GMT References: <1771@mindlink.UUCP> <2574@skye.ed.ac.uk> <3078@goanna.cs.rmit.oz.au> Reply-To: steve@taumet.UUCP (Stephen Clamage) Organization: Taumetric Corporation, San Diego Lines: 20 In article <3078@goanna.cs.rmit.oz.au> ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes: >I have a data structure containing >some pointers, and *I* have filled some of them in >and the caller preset some of them to defaults. Now I'm going to change >one of them. Should I free it? ... >Can anyone suggest a better way of tackling this problem in portable C? This is easy to handle (safely and portably) in C++ (which is not precisely the question you asked). In the constructor for the data structure, you set a private boolean that says whether a the data pointed-to needs to be freed. The destructor, and each member function which modifies the structure, checks the boolean to see whether to free the data. These functions are written once while the design is fresh in your mind. Forever after, only the member functions are used to modify the data, and no user of the data type ever needs to think about freeing the data. -- Steve Clamage, TauMetric Corp, steve@taumet.com