Commit 061732ad authored by Tatsuhiko Kubo's avatar Tatsuhiko Kubo

improved malloc error handlings.

parent 5c2ca287
...@@ -57,6 +57,9 @@ json_t *dump_header(const uint8_t *name, size_t namelen, const uint8_t *value, ...@@ -57,6 +57,9 @@ json_t *dump_header(const uint8_t *name, size_t namelen, const uint8_t *value,
size_t valuelen) { size_t valuelen) {
json_t *nv_pair = json_object(); json_t *nv_pair = json_object();
char *cname = malloc(namelen + 1); char *cname = malloc(namelen + 1);
if (cname == NULL) {
return NULL;
}
memcpy(cname, name, namelen); memcpy(cname, name, namelen);
cname[namelen] = '\0'; cname[namelen] = '\0';
json_object_set_new(nv_pair, cname, json_pack("s#", value, valuelen)); json_object_set_new(nv_pair, cname, json_pack("s#", value, valuelen));
......
...@@ -737,10 +737,16 @@ char *get_exec_path(int argc, char **const argv, const char *cwd) { ...@@ -737,10 +737,16 @@ char *get_exec_path(int argc, char **const argv, const char *cwd) {
if (argv0[0] == '/') { if (argv0[0] == '/') {
path = static_cast<char *>(malloc(len + 1)); path = static_cast<char *>(malloc(len + 1));
if (path == NULL) {
return NULL;
}
memcpy(path, argv0, len + 1); memcpy(path, argv0, len + 1);
} else { } else {
auto cwdlen = strlen(cwd); auto cwdlen = strlen(cwd);
path = static_cast<char *>(malloc(len + 1 + cwdlen + 1)); path = static_cast<char *>(malloc(len + 1 + cwdlen + 1));
if (path == NULL) {
return NULL;
}
memcpy(path, cwd, cwdlen); memcpy(path, cwd, cwdlen);
path[cwdlen] = '/'; path[cwdlen] = '/';
memcpy(path + cwdlen + 1, argv0, len + 1); memcpy(path + cwdlen + 1, argv0, len + 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment