mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
call virReportOOMError when appropriate in hash.c
A couple of allocation were not calling virReportOOMError on allocation errors * src/util/hash.c: add the needed call in virHashCreate and virHashAddOrUpdateEntry
This commit is contained in:
parent
b958419534
commit
7adb3fb739
@ -27,6 +27,8 @@
|
|||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
|
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||||
|
|
||||||
#define MAX_HASH_LEN 8
|
#define MAX_HASH_LEN 8
|
||||||
|
|
||||||
/* #define DEBUG_GROW */
|
/* #define DEBUG_GROW */
|
||||||
@ -88,12 +90,15 @@ virHashCreate(int size)
|
|||||||
if (size <= 0)
|
if (size <= 0)
|
||||||
size = 256;
|
size = 256;
|
||||||
|
|
||||||
if (VIR_ALLOC(table) < 0)
|
if (VIR_ALLOC(table) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
table->size = size;
|
table->size = size;
|
||||||
table->nbElems = 0;
|
table->nbElems = 0;
|
||||||
if (VIR_ALLOC_N(table->table, size) < 0) {
|
if (VIR_ALLOC_N(table->table, size) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
VIR_FREE(table);
|
VIR_FREE(table);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -135,6 +140,7 @@ virHashGrow(virHashTablePtr table, int size)
|
|||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (VIR_ALLOC_N(table->table, size) < 0) {
|
if (VIR_ALLOC_N(table->table, size) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
table->table = oldtable;
|
table->table = oldtable;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
@ -278,12 +284,15 @@ virHashAddEntry(virHashTablePtr table, const char *name, void *userdata)
|
|||||||
if (insert == NULL) {
|
if (insert == NULL) {
|
||||||
entry = &(table->table[key]);
|
entry = &(table->table[key]);
|
||||||
} else {
|
} else {
|
||||||
if (VIR_ALLOC(entry) < 0)
|
if (VIR_ALLOC(entry) < 0) {
|
||||||
|
virReportOOMError();
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
new_name = strdup(name);
|
new_name = strdup(name);
|
||||||
if (new_name == NULL) {
|
if (new_name == NULL) {
|
||||||
|
virReportOOMError();
|
||||||
if (insert != NULL)
|
if (insert != NULL)
|
||||||
VIR_FREE(entry);
|
VIR_FREE(entry);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
Loading…
Reference in New Issue
Block a user