From 96944f11116e2196dd3d76d0960bcd1613be0281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexe=C3=AF=20KADIR?= Date: Sat, 24 Feb 2024 02:50:22 +0100 Subject: [PATCH] Added some checks --- src/sandbox.c | 1 - src/xml.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sandbox.c b/src/sandbox.c index 4252784..f4d1c97 100755 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -3,7 +3,6 @@ #include "utils.h" #include "backing.h" #include "container.h" -#include "domain.h" #include #include diff --git a/src/xml.c b/src/xml.c index a8553e7..031ce52 100644 --- a/src/xml.c +++ b/src/xml.c @@ -5,6 +5,8 @@ #include #include +#include +#include result_t generate_domain_xml(char** _xml, const char* container, uint64_t memory, int vcpus, const char** pci_addresses, const char** iso_paths, int vnc_port, const char* vnc_password) { // Initialize the output parameters @@ -132,7 +134,14 @@ result_t generate_pci_xml(char** _xml, const char** pci_addresses) { return result; // Generate the XML configuration for the PCI devices + errno = 0; char* xml = strdup(""); + if (xml == NULL) { + for (int i = 0; pci_devices[i] != NULL; i++) + free(pci_devices[i]); + free(pci_devices); + return failure("Failed to allocate memory for the initial XML configuration (%s).", strerror(errno)); + } // For each PCI device, generate the XML configuration, and append it to the result for (int i = 0; pci_devices[i] != NULL; i++) { @@ -195,7 +204,10 @@ result_t generate_iso_xml(char** _xml, const char** iso_paths) { *_xml = NULL; // Generate the XML configuration for the ISO images + errno = 0; char* xml = strdup(""); + if (xml == NULL) + return failure("Failed to allocate memory for the initial XML configuration (%s).", strerror(errno)); // For each ISO image, generate the XML configuration, and append it to the result for (int i = 0; iso_paths[i] != NULL; i++) {