about summary refs log tree commit homepage
path: root/http_put.c
diff options
context:
space:
mode:
Diffstat (limited to 'http_put.c')
-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) {