Coverity reports that there is a memory leak in
ioreq_server_alloc_rangesets(). This would be true if Xen's implementation of
asprintf() had glibc's return semantics, but it doesn't.
Rename to xasprintf() to reduce confusion for Coverity and other developers.
While at it, fix style issues. Rearrange ioreq_server_alloc_rangesets() to
use a tabulated switch statement, and not to have a trailing space in the
rangeset name for an unknown range type.
Coverity-ID:
1472735
Coverity-ID:
1500265
Fixes: 780e918a2e54 ("add an implentation of asprintf() for xen")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
for ( i = 0; i < NR_IO_RANGE_TYPES; i++ )
{
- char *name;
+ char *name, *type;
- rc = asprintf(&name, "ioreq_server %d %s", id,
- (i == XEN_DMOP_IO_RANGE_PORT) ? "port" :
- (i == XEN_DMOP_IO_RANGE_MEMORY) ? "memory" :
- (i == XEN_DMOP_IO_RANGE_PCI) ? "pci" :
- "");
+ switch ( i )
+ {
+ case XEN_DMOP_IO_RANGE_PORT: type = " port"; break;
+ case XEN_DMOP_IO_RANGE_MEMORY: type = " memory"; break;
+ case XEN_DMOP_IO_RANGE_PCI: type = " pci"; break;
+ default: type = ""; break;
+ }
+
+ rc = xasprintf(&name, "ioreq_server %d%s", id, type);
if ( rc )
goto fail;
EXPORT_SYMBOL(scnprintf);
/**
- * vasprintf - Format a string and allocate a buffer to place it in
+ * xvasprintf - Format a string and allocate a buffer to place it in
*
* @bufp: Pointer to a pointer to receive the allocated buffer
* @fmt: The format string to use
* guaranteed to be null terminated. The memory is allocated
* from xenheap, so the buffer should be freed with xfree().
*/
-int vasprintf(char **bufp, const char *fmt, va_list args)
+int xvasprintf(char **bufp, const char *fmt, va_list args)
{
va_list args_copy;
size_t size;
}
/**
- * asprintf - Format a string and place it in a buffer
+ * xasprintf - Format a string and place it in a buffer
* @bufp: Pointer to a pointer to receive the allocated buffer
* @fmt: The format string to use
* @...: Arguments for the format string
* guaranteed to be null terminated. The memory is allocated
* from xenheap, so the buffer should be freed with xfree().
*/
-int asprintf(char **bufp, const char *fmt, ...)
+int xasprintf(char **bufp, const char *fmt, ...)
{
va_list args;
int i;
va_start(args, fmt);
- i=vasprintf(bufp,fmt,args);
+ i = xvasprintf(bufp, fmt, args);
va_end(args);
+
return i;
}
__attribute__ ((format (printf, 3, 4)));
extern int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
__attribute__ ((format (printf, 3, 0)));
-extern int asprintf(char ** bufp, const char * fmt, ...)
+extern int xasprintf(char **bufp, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
-extern int vasprintf(char ** bufp, const char * fmt, va_list args)
+extern int xvasprintf(char **bufp, const char *fmt, va_list args)
__attribute__ ((format (printf, 2, 0)));
long simple_strtol(