Check return values from memory allocation

This commit is contained in:
Eric Fischer
2016-03-25 11:57:33 -07:00
parent bc5a7b251f
commit eee596d5f5
4 changed files with 89 additions and 7 deletions
+44 -6
View File
@@ -141,6 +141,10 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
pool_init(&((*file_keys)[ll]), 0);
(*layernames)[ll] = strdup(ln);
if ((*layernames)[ll] == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
*nlayers = ll + 1;
}
@@ -161,6 +165,10 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
if (val.has_string_value()) {
value = strdup(val.string_value().c_str());
if (value == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
type = VT_STRING;
} else if (val.has_int_value()) {
if (asprintf(&value, "%lld", (long long) val.int_value()) >= 0) {
@@ -196,7 +204,12 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
if (!is_pooled(exclude, key, VT_STRING)) {
if (!is_pooled(&((*file_keys)[ll]), key, type)) {
pool(&((*file_keys)[ll]), strdup(key), type);
char *copy = strdup(key);
if (copy == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
pool(&((*file_keys)[ll]), copy, type);
}
struct pool_val *k, *v;
@@ -204,13 +217,23 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
if (is_pooled(&keys, key, VT_STRING)) {
k = pool(&keys, key, VT_STRING);
} else {
k = pool(&keys, strdup(key), VT_STRING);
char *copy = strdup(key);
if (copy == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
k = pool(&keys, copy, VT_STRING);
}
if (is_pooled(&values, value, type)) {
v = pool(&values, value, type);
} else {
v = pool(&values, strdup(value), type);
char *copy = strdup(value);
if (copy == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
v = pool(&values, copy, type);
}
feature_tags.push_back(k->n);
@@ -242,7 +265,12 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
if (!is_pooled(exclude, sjoinkey, VT_STRING)) {
if (!is_pooled(&((*file_keys)[ll]), sjoinkey, type)) {
pool(&((*file_keys)[ll]), strdup(sjoinkey), type);
char *copy = strdup(sjoinkey);
if (copy == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
pool(&((*file_keys)[ll]), copy, type);
}
struct pool_val *k, *v;
@@ -250,13 +278,23 @@ void handle(std::string message, int z, unsigned x, unsigned y, struct pool **fi
if (is_pooled(&keys, sjoinkey, VT_STRING)) {
k = pool(&keys, sjoinkey, VT_STRING);
} else {
k = pool(&keys, strdup(sjoinkey), VT_STRING);
char *copy = strdup(sjoinkey);
if (copy == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
k = pool(&keys, copy, VT_STRING);
}
if (is_pooled(&values, sjoinval, type)) {
v = pool(&values, sjoinval, type);
} else {
v = pool(&values, strdup(sjoinval), type);
char *copy = strdup(sjoinval);
if (copy == NULL) {
perror("Out of memory");
exit(EXIT_FAILURE);
}
v = pool(&values, copy, type);
}
feature_tags.push_back(k->n);