about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-06-01 22:32:37 +0000
committerEric Wong <e@80x24.org>2016-06-05 08:47:49 +0000
commit504a5ced05f48bf8cc1a08b22ce8830b6db98d41 (patch)
treea1369d5a4866e623d20242ee00763ec36200f23d
parenta03ccc608f68f44122f83dbde7bb09e9acbbc185 (diff)
downloadcmogstored-504a5ced05f48bf8cc1a08b22ce8830b6db98d41.tar.gz
Failing to allocate memory should be a temporary error and be
non-fatal.
-rw-r--r--http_put.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/http_put.c b/http_put.c
index 92bc435..5084090 100644
--- a/http_put.c
+++ b/http_put.c
@@ -306,6 +306,8 @@ MOG_NOINLINE static void rnd_init_per_thread(void)
 static char *tmppath_for(struct mog_http *http, const char *path)
 {
         int32_t result;
+        int rc;
+        char *s;
 
         if (!rnd.ready)
                 rnd_init_per_thread();
@@ -313,8 +315,10 @@ static char *tmppath_for(struct mog_http *http, const char *path)
         assert(http && "validation later"); /* TODO */
         CHECK(int, 0, random_r(&rnd.data, &result));
 
-        return xasprintf("%s.%08x.%d.tmp",
-                         path, (unsigned)result, (int)getpid());
+        rc = asprintf(&s, "%s.%08x.%d.tmp",
+                        path, (unsigned)result, (int)getpid());
+
+        return rc >= 0 ? s : 0;
 }
 
 static struct mog_file * open_put(struct mog_http *http, char *path)
@@ -337,12 +341,17 @@ static struct mog_file * open_put(struct mog_http *http, char *path)
                 char *tmp = tmppath_for(http, path);
                 int fl = O_EXCL | O_TRUNC | O_CREAT;
 
+                if (!tmp)
+                        return NULL;
+
                 http->forward = mog_file_open_put(http->svc, tmp, fl);
 
                 /* retry once on EEXIST, don't inf loop if RNG is broken */
                 if (http->forward == NULL && errno == EEXIST) {
                         free(tmp);
                         tmp = tmppath_for(http, path);
+                        if (!tmp)
+                                return NULL;
                         http->forward = mog_file_open_put(http->svc, tmp, fl);
                 }
                 if (http->forward == NULL) {