mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 09:14:57 +00:00
util: Get rid of "no_memory" labels
As pointed out by Ján Tomko, "no_memory seems suspicious in the times of abort()". As libvirt decided to take the path to not report OOM and simply abort when it happens, let's get rid of the no_memory labels and simplify the code around them. Mind that virfirewall.c was not touched and still contains no_memory labels. The reason those are left behind, at least for now, is because the conversion seems to be slightly more complicated than the rest, as some other places are relying on firewall->err being set to ENOMEM. Reviewed-by: Cole Robinson <crobinso@redhat.com> Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
This commit is contained in:
parent
c671e03ffa
commit
cee3a900a0
@ -302,33 +302,27 @@ virSysinfoParsePPCProcessor(const char *base, virSysinfoDefPtr ret)
|
|||||||
virSysinfoDefPtr
|
virSysinfoDefPtr
|
||||||
virSysinfoReadPPC(void)
|
virSysinfoReadPPC(void)
|
||||||
{
|
{
|
||||||
virSysinfoDefPtr ret = NULL;
|
g_auto(virSysinfoDefPtr) ret = NULL;
|
||||||
char *outbuf = NULL;
|
g_autofree char *outbuf = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to open %s"), CPUINFO);
|
_("Failed to open %s"), CPUINFO);
|
||||||
goto no_memory;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->nprocessor = 0;
|
ret->nprocessor = 0;
|
||||||
ret->processor = NULL;
|
ret->processor = NULL;
|
||||||
if (virSysinfoParsePPCProcessor(outbuf, ret) < 0)
|
if (virSysinfoParsePPCProcessor(outbuf, ret) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0)
|
if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
VIR_FREE(outbuf);
|
return g_steal_pointer(&ret);
|
||||||
return ret;
|
|
||||||
|
|
||||||
no_memory:
|
|
||||||
VIR_FREE(outbuf);
|
|
||||||
virSysinfoDefFree(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -433,13 +427,13 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
|
|||||||
virSysinfoDefPtr
|
virSysinfoDefPtr
|
||||||
virSysinfoReadARM(void)
|
virSysinfoReadARM(void)
|
||||||
{
|
{
|
||||||
virSysinfoDefPtr ret = NULL;
|
g_auto(virSysinfoDefPtr) ret = NULL;
|
||||||
char *outbuf = NULL;
|
g_autofree char *outbuf = NULL;
|
||||||
|
|
||||||
/* Some ARM systems have DMI tables available. */
|
/* Some ARM systems have DMI tables available. */
|
||||||
if ((ret = virSysinfoReadDMI())) {
|
if ((ret = virSysinfoReadDMI())) {
|
||||||
if (!virSysinfoDefIsEmpty(ret))
|
if (!virSysinfoDefIsEmpty(ret))
|
||||||
return ret;
|
return g_steal_pointer(&ret);
|
||||||
virSysinfoDefFree(ret);
|
virSysinfoDefFree(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,29 +441,23 @@ virSysinfoReadARM(void)
|
|||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to open %s"), CPUINFO);
|
_("Failed to open %s"), CPUINFO);
|
||||||
goto no_memory;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->nprocessor = 0;
|
ret->nprocessor = 0;
|
||||||
ret->processor = NULL;
|
ret->processor = NULL;
|
||||||
if (virSysinfoParseARMProcessor(outbuf, ret) < 0)
|
if (virSysinfoParseARMProcessor(outbuf, ret) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0)
|
if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
VIR_FREE(outbuf);
|
return g_steal_pointer(&ret);
|
||||||
return ret;
|
|
||||||
|
|
||||||
no_memory:
|
|
||||||
VIR_FREE(outbuf);
|
|
||||||
virSysinfoDefFree(ret);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
@ -606,21 +594,21 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
|
|||||||
virSysinfoDefPtr
|
virSysinfoDefPtr
|
||||||
virSysinfoReadS390(void)
|
virSysinfoReadS390(void)
|
||||||
{
|
{
|
||||||
virSysinfoDefPtr ret = NULL;
|
g_auto(virSysinfoDefPtr) ret = NULL;
|
||||||
char *outbuf = NULL;
|
g_autofree char *outbuf = NULL;
|
||||||
|
|
||||||
if (VIR_ALLOC(ret) < 0)
|
if (VIR_ALLOC(ret) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
/* Gather info from /proc/cpuinfo */
|
/* Gather info from /proc/cpuinfo */
|
||||||
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to open %s"), CPUINFO);
|
_("Failed to open %s"), CPUINFO);
|
||||||
goto no_memory;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSysinfoParseS390Processor(outbuf, ret) < 0)
|
if (virSysinfoParseS390Processor(outbuf, ret) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
/* Free buffer before reading next file */
|
/* Free buffer before reading next file */
|
||||||
VIR_FREE(outbuf);
|
VIR_FREE(outbuf);
|
||||||
@ -629,19 +617,13 @@ virSysinfoReadS390(void)
|
|||||||
if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) {
|
if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Failed to open %s"), SYSINFO);
|
_("Failed to open %s"), SYSINFO);
|
||||||
goto no_memory;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virSysinfoParseS390System(outbuf, &ret->system) < 0)
|
if (virSysinfoParseS390System(outbuf, &ret->system) < 0)
|
||||||
goto no_memory;
|
return NULL;
|
||||||
|
|
||||||
VIR_FREE(outbuf);
|
return g_steal_pointer(&ret);
|
||||||
return ret;
|
|
||||||
|
|
||||||
no_memory:
|
|
||||||
virSysinfoDefFree(ret);
|
|
||||||
VIR_FREE(outbuf);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,6 +144,8 @@ void virSysinfoChassisDefFree(virSysinfoChassisDefPtr def);
|
|||||||
void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDefPtr def);
|
void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDefPtr def);
|
||||||
void virSysinfoDefFree(virSysinfoDefPtr def);
|
void virSysinfoDefFree(virSysinfoDefPtr def);
|
||||||
|
|
||||||
|
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(virSysinfoDefPtr, virSysinfoDefFree, NULL);
|
||||||
|
|
||||||
int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||||
|
|
||||||
|
@ -71,7 +71,8 @@ virURIParseParams(virURIPtr uri)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (*query) {
|
while (*query) {
|
||||||
char *name = NULL, *value = NULL;
|
g_autofree char *name = NULL;
|
||||||
|
g_autofree char *value = NULL;
|
||||||
|
|
||||||
/* Find the next separator, or end of the string. */
|
/* Find the next separator, or end of the string. */
|
||||||
end = strchr(query, '&');
|
end = strchr(query, '&');
|
||||||
@ -92,13 +93,15 @@ virURIParseParams(virURIPtr uri)
|
|||||||
* and consistent with CGI.pm we assume value is "".
|
* and consistent with CGI.pm we assume value is "".
|
||||||
*/
|
*/
|
||||||
name = xmlURIUnescapeString(query, end - query, NULL);
|
name = xmlURIUnescapeString(query, end - query, NULL);
|
||||||
if (!name) goto no_memory;
|
if (!name)
|
||||||
|
return -1;
|
||||||
} else if (eq+1 == end) {
|
} else if (eq+1 == end) {
|
||||||
/* Or if we have "name=" here (works around annoying
|
/* Or if we have "name=" here (works around annoying
|
||||||
* problem when calling xmlURIUnescapeString with len = 0).
|
* problem when calling xmlURIUnescapeString with len = 0).
|
||||||
*/
|
*/
|
||||||
name = xmlURIUnescapeString(query, eq - query, NULL);
|
name = xmlURIUnescapeString(query, eq - query, NULL);
|
||||||
if (!name) goto no_memory;
|
if (!name)
|
||||||
|
return -1;
|
||||||
} else if (query == eq) {
|
} else if (query == eq) {
|
||||||
/* If the '=' character is at the beginning then we have
|
/* If the '=' character is at the beginning then we have
|
||||||
* "=value" and consistent with CGI.pm we _ignore_ this.
|
* "=value" and consistent with CGI.pm we _ignore_ this.
|
||||||
@ -108,22 +111,15 @@ virURIParseParams(virURIPtr uri)
|
|||||||
/* Otherwise it's "name=value". */
|
/* Otherwise it's "name=value". */
|
||||||
name = xmlURIUnescapeString(query, eq - query, NULL);
|
name = xmlURIUnescapeString(query, eq - query, NULL);
|
||||||
if (!name)
|
if (!name)
|
||||||
goto no_memory;
|
return -1;
|
||||||
value = xmlURIUnescapeString(eq+1, end - (eq+1), NULL);
|
value = xmlURIUnescapeString(eq+1, end - (eq+1), NULL);
|
||||||
if (!value) {
|
if (!value)
|
||||||
VIR_FREE(name);
|
return -1;
|
||||||
goto no_memory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append to the parameter set. */
|
/* Append to the parameter set. */
|
||||||
if (virURIParamAppend(uri, name, NULLSTR_EMPTY(value)) < 0) {
|
if (virURIParamAppend(uri, name, NULLSTR_EMPTY(value)) < 0)
|
||||||
VIR_FREE(name);
|
|
||||||
VIR_FREE(value);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
VIR_FREE(name);
|
|
||||||
VIR_FREE(value);
|
|
||||||
|
|
||||||
next:
|
next:
|
||||||
query = end;
|
query = end;
|
||||||
@ -131,10 +127,6 @@ virURIParseParams(virURIPtr uri)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
|
||||||
virReportOOMError();
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user