Path: utzoo!attcan!uunet!cs.utexas.edu!sun-barr!newstop!sun!ingersoll!sxn From: sxn%ingersoll@Sun.COM (Stephen X. Nahm) Newsgroups: comp.protocols.nfs Subject: Re: Is there a convention for the use of xdr_destroy() and xdr_free()? Keywords: xdr_destroy xdr_free Message-ID: <128366@sun.Eng.Sun.COM> Date: 25 Nov 89 03:48:49 GMT References: <21476@ppgbms.UUCP> Sender: news@sun.Eng.Sun.COM Distribution: na Lines: 74 paul@ppgbms (Paul Evan Matz) writes: >I assume this is the right group to ask this question, since NFS is built >using rpc and xdr (and if not the right group, please direct me to the >proper one). It's as good a place as any... >I gather that xdr_free() frees any memory malloced during an XDR_DECODE >operation (for strings, etc.), Right: xdr_free() frees any temporarily allocated memory space used by the XDR encoding/decoding routine when processing an object (usually strings and pointers). After calling xdr_free(), you shouldn't reference the object anymore. Here's the man page entry for xdr_free() (from SunOS 4.0 or RPCSRC 4.0): void xdr_free(proc, objp) xdrproc_t proc; char *objp; Generic freeing routine. The first argument is the XDR routine for the object being freed. The second argument is a pointer to the object itself. Note: the pointer passed to this routine is not freed, but what it points to is freed (recursively). > and that xdr_destroy() is the inverse of >the xdrxxx_create() calls. What exactly is destroyed? Clearly not the >"XDR xdrs;" auto variable. Perhaps just the data area pointed to by >x_private? It depends on the XDR stream. Here's the destroy routine from the xdrmem stream type (memory stream are used when sending data to the net): static void xdrmem_destroy(/*xdrs*/) /*XDR *xdrs;*/ { } That is, it does nothing. (It's static because it is called via a dispatch table, not directly.) Here's the xdrstdio version of destroy (STDIO streams are used to send data to files): /* * Destroy a stdio xdr stream. * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create. */ static void xdrstdio_destroy(xdrs) register XDR *xdrs; { (void)fflush((FILE *)xdrs->x_private); /* xx should we close the file ?? */ }; That is, it flushes the STDIO stream. The implementor could have indeed closed the STDIO stream, since the intention of xdr_destroy() is that the XDR stream will no longer be used. Here's the man page entry: void xdr_destroy(xdrs) XDR *xdrs; A macro that invokes the destroy routine associated with the XDR stream, xdrs. Destruction usually involves freeing private data structures associated with the stream. Using xdrs after invoking xdr_destroy() is undefined. Steve Nahm sxn@sun.COM or sun!sxn