mirror of https://gitee.com/openkylin/libvirt.git
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
|
||||
virSysinfoReadPPC(void)
|
||||
{
|
||||
virSysinfoDefPtr ret = NULL;
|
||||
char *outbuf = NULL;
|
||||
g_auto(virSysinfoDefPtr) ret = NULL;
|
||||
g_autofree char *outbuf = NULL;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to open %s"), CPUINFO);
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->nprocessor = 0;
|
||||
ret->processor = NULL;
|
||||
if (virSysinfoParsePPCProcessor(outbuf, ret) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
VIR_FREE(outbuf);
|
||||
return ret;
|
||||
|
||||
no_memory:
|
||||
VIR_FREE(outbuf);
|
||||
virSysinfoDefFree(ret);
|
||||
return NULL;
|
||||
return g_steal_pointer(&ret);
|
||||
}
|
||||
|
||||
|
||||
|
@ -433,13 +427,13 @@ virSysinfoParseARMProcessor(const char *base, virSysinfoDefPtr ret)
|
|||
virSysinfoDefPtr
|
||||
virSysinfoReadARM(void)
|
||||
{
|
||||
virSysinfoDefPtr ret = NULL;
|
||||
char *outbuf = NULL;
|
||||
g_auto(virSysinfoDefPtr) ret = NULL;
|
||||
g_autofree char *outbuf = NULL;
|
||||
|
||||
/* Some ARM systems have DMI tables available. */
|
||||
if ((ret = virSysinfoReadDMI())) {
|
||||
if (!virSysinfoDefIsEmpty(ret))
|
||||
return ret;
|
||||
return g_steal_pointer(&ret);
|
||||
virSysinfoDefFree(ret);
|
||||
}
|
||||
|
||||
|
@ -447,29 +441,23 @@ virSysinfoReadARM(void)
|
|||
virResetLastError();
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to open %s"), CPUINFO);
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret->nprocessor = 0;
|
||||
ret->processor = NULL;
|
||||
if (virSysinfoParseARMProcessor(outbuf, ret) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
VIR_FREE(outbuf);
|
||||
return ret;
|
||||
|
||||
no_memory:
|
||||
VIR_FREE(outbuf);
|
||||
virSysinfoDefFree(ret);
|
||||
return NULL;
|
||||
return g_steal_pointer(&ret);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -606,21 +594,21 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
|
|||
virSysinfoDefPtr
|
||||
virSysinfoReadS390(void)
|
||||
{
|
||||
virSysinfoDefPtr ret = NULL;
|
||||
char *outbuf = NULL;
|
||||
g_auto(virSysinfoDefPtr) ret = NULL;
|
||||
g_autofree char *outbuf = NULL;
|
||||
|
||||
if (VIR_ALLOC(ret) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
/* Gather info from /proc/cpuinfo */
|
||||
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to open %s"), CPUINFO);
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virSysinfoParseS390Processor(outbuf, ret) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
/* Free buffer before reading next file */
|
||||
VIR_FREE(outbuf);
|
||||
|
@ -629,19 +617,13 @@ virSysinfoReadS390(void)
|
|||
if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to open %s"), SYSINFO);
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virSysinfoParseS390System(outbuf, &ret->system) < 0)
|
||||
goto no_memory;
|
||||
return NULL;
|
||||
|
||||
VIR_FREE(outbuf);
|
||||
return ret;
|
||||
|
||||
no_memory:
|
||||
virSysinfoDefFree(ret);
|
||||
VIR_FREE(outbuf);
|
||||
return NULL;
|
||||
return g_steal_pointer(&ret);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -144,6 +144,8 @@ void virSysinfoChassisDefFree(virSysinfoChassisDefPtr def);
|
|||
void virSysinfoOEMStringsDefFree(virSysinfoOEMStringsDefPtr def);
|
||||
void virSysinfoDefFree(virSysinfoDefPtr def);
|
||||
|
||||
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(virSysinfoDefPtr, virSysinfoDefFree, NULL);
|
||||
|
||||
int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ virURIParseParams(virURIPtr uri)
|
|||
return 0;
|
||||
|
||||
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. */
|
||||
end = strchr(query, '&');
|
||||
|
@ -92,13 +93,15 @@ virURIParseParams(virURIPtr uri)
|
|||
* and consistent with CGI.pm we assume value is "".
|
||||
*/
|
||||
name = xmlURIUnescapeString(query, end - query, NULL);
|
||||
if (!name) goto no_memory;
|
||||
if (!name)
|
||||
return -1;
|
||||
} else if (eq+1 == end) {
|
||||
/* Or if we have "name=" here (works around annoying
|
||||
* problem when calling xmlURIUnescapeString with len = 0).
|
||||
*/
|
||||
name = xmlURIUnescapeString(query, eq - query, NULL);
|
||||
if (!name) goto no_memory;
|
||||
if (!name)
|
||||
return -1;
|
||||
} else if (query == eq) {
|
||||
/* If the '=' character is at the beginning then we have
|
||||
* "=value" and consistent with CGI.pm we _ignore_ this.
|
||||
|
@ -108,22 +111,15 @@ virURIParseParams(virURIPtr uri)
|
|||
/* Otherwise it's "name=value". */
|
||||
name = xmlURIUnescapeString(query, eq - query, NULL);
|
||||
if (!name)
|
||||
goto no_memory;
|
||||
return -1;
|
||||
value = xmlURIUnescapeString(eq+1, end - (eq+1), NULL);
|
||||
if (!value) {
|
||||
VIR_FREE(name);
|
||||
goto no_memory;
|
||||
}
|
||||
if (!value)
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Append to the parameter set. */
|
||||
if (virURIParamAppend(uri, name, NULLSTR_EMPTY(value)) < 0) {
|
||||
VIR_FREE(name);
|
||||
VIR_FREE(value);
|
||||
if (virURIParamAppend(uri, name, NULLSTR_EMPTY(value)) < 0)
|
||||
return -1;
|
||||
}
|
||||
VIR_FREE(name);
|
||||
VIR_FREE(value);
|
||||
|
||||
next:
|
||||
query = end;
|
||||
|
@ -131,10 +127,6 @@ virURIParseParams(virURIPtr uri)
|
|||
}
|
||||
|
||||
return 0;
|
||||
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue