Added some checks

This commit is contained in:
Alexei KADIR 2024-02-24 02:50:22 +01:00
parent 18eefa93c3
commit 96944f1111
2 changed files with 12 additions and 1 deletions

View File

@ -3,7 +3,6 @@
#include "utils.h" #include "utils.h"
#include "backing.h" #include "backing.h"
#include "container.h" #include "container.h"
#include "domain.h"
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>

View File

@ -5,6 +5,8 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <errno.h>
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) { 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 // Initialize the output parameters
@ -132,7 +134,14 @@ result_t generate_pci_xml(char** _xml, const char** pci_addresses) {
return result; return result;
// Generate the XML configuration for the PCI devices // Generate the XML configuration for the PCI devices
errno = 0;
char* xml = strdup(""); 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 each PCI device, generate the XML configuration, and append it to the result
for (int i = 0; pci_devices[i] != NULL; i++) { 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; *_xml = NULL;
// Generate the XML configuration for the ISO images // Generate the XML configuration for the ISO images
errno = 0;
char* xml = strdup(""); 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 each ISO image, generate the XML configuration, and append it to the result
for (int i = 0; iso_paths[i] != NULL; i++) { for (int i = 0; iso_paths[i] != NULL; i++) {