OpenAFS Master Repository branch, master, updated. openafs-devel-1_9_1-431-g986de6c
Gerrit Code Review
gerrit@openafs.org
Wed, 3 Jul 2024 15:14:03 -0400
The following commit has been merged in the master branch:
commit 986de6cfdc84468c3d1e106ee7af014015b11102
Author: Andrew Deason <adeason@sinenomine.net>
Date: Mon Oct 28 11:44:04 2019 -0500
rxgen: Introduce xdrfree_type()
Currently, the most common way to free an object allocated by xdr is
to call:
xdr_free((xdrproc_t) xdr_foo, &foo);
Which runs the given object through the xdr routines with the XDR_FREE
operation. This works, but is not typesafe; if the wrong xdr_foo
routine is given to xdr_free, we will silently run the wrong xdr
routines, potentially freeing corrupt memory, etc.
It is easy to make this mistake when dealing with many different XDR
types, or dealing with various levels of indirection (e.g. an array of
pointers to ...). It is also easy to make mistakes with strings;
xdr_string() isn't really appropriate to give to xdr_free(), since
xdr_string() takes 3 arguments, instead of the 2 arguments of most
other xdr_type() routines. Commit bbb1e8adfe (xdr: Avoid xdr_string
maxsize check when freeing) is an example of these issues.
There is a typesafe way to free an xdr object, if the caller basically
copies the implementation of xdr_free():
{
XDR x;
x.x_op = XDR_FREE;
(void)xdr_foo(&x, &foo);
}
But this is rather cumbersome, and so is uncommon.
To allow convenient freeing of xdr objects in a typesafe manner,
introduce a generated function for each xdr type, called
xdrfree_type(). This should result in the same behavior as xdr_free(),
but does so in a typesafe manner and avoids the weird quirks with
xdrproc_t and AFS_XDRPROC_NO_VARARG.
Also define xdrfree_string(), to allow for convenient typesafe freeing
of XDR strings directly.
This commit does not add any calls to xdrfree_type(), but future
commits will do so.
Change-Id: Icf34e6de5d0da2b43b3e8ad3dc1acc74ef0e61dd
Reviewed-on: https://gerrit.openafs.org/15497
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
src/rx/xdr.c | 9 +++++++++
src/rx/xdr_prototypes.h | 1 +
src/rxgen/rpc_cout.c | 18 ++++++++++++++++++
src/rxgen/rpc_hout.c | 2 ++
4 files changed, 30 insertions(+)
--
OpenAFS Master Repository