mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
commandhelper: Use automatic memory management in printEnvironment
Signed-off-by: Tim Wiederhake <twiederh@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
368afd0bb6
commit
0793d15685
@ -54,6 +54,12 @@ static void cleanupArguments(struct Arguments **ptr)
|
|||||||
free(args);
|
free(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void cleanupGeneric(void *ptr)
|
||||||
|
{
|
||||||
|
void **ptrptr = ptr;
|
||||||
|
free (*ptrptr);
|
||||||
|
}
|
||||||
|
|
||||||
static struct Arguments *parseArguments(int argc, char** argv)
|
static struct Arguments *parseArguments(int argc, char** argv)
|
||||||
{
|
{
|
||||||
cleanup(struct Arguments *, cleanupArguments) args = NULL;
|
cleanup(struct Arguments *, cleanupArguments) args = NULL;
|
||||||
@ -124,16 +130,15 @@ static int envsort(const void *a, const void *b)
|
|||||||
|
|
||||||
static int printEnvironment(FILE *log)
|
static int printEnvironment(FILE *log)
|
||||||
{
|
{
|
||||||
char **newenv;
|
cleanup(char **, cleanupGeneric) newenv = NULL;
|
||||||
size_t length;
|
size_t length;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
for (length = 0; environ[length]; length++) {
|
for (length = 0; environ[length]; length++) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(newenv = malloc(sizeof(*newenv) * length)))
|
if (!(newenv = malloc(sizeof(*newenv) * length)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < length; i++) {
|
for (i = 0; i < length; i++) {
|
||||||
newenv[i] = environ[i];
|
newenv[i] = environ[i];
|
||||||
@ -148,12 +153,7 @@ static int printEnvironment(FILE *log)
|
|||||||
fprintf(log, "ENV:%s\n", newenv[i]);
|
fprintf(log, "ENV:%s\n", newenv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
if (newenv)
|
|
||||||
free(newenv);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int printFds(FILE *log)
|
static int printFds(FILE *log)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user