
On Mon, Dec 01, 2008 at 12:03:39AM +0000, Daniel P. Berrange wrote:
This patch reduces the number of return paths in the node device driver methods
In doing this I noticed an annoying problem in the public API contract for virNodeDeviceGetParent. It returns a 'const char *', but the remote driver is actually returning an malloc'd string requiring the caller to free it, while the node_device driver is returning a const string the caller must not free. Ideally we would not have the 'const' annotation but changing that now is ABI change, so instead I work around it, by making all drivers return a malloc'd string, but then caching this in the virNodeDevicePtr object. This mallc'd string is then free'd when the object is released. This allows us to work around the public API contract problem
argh, understood ! [...]
static char *nodeDeviceGetParent(virNodeDevicePtr dev) { [...] - return obj->def->parent; + ret = strdup(obj->def->parent);
I guess we should report allocation error, even if it probably doesn't help much at that point.
+cleanup: + return ret; }
Okay +1, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/