cmogstored dev/user discussion/issues/patches/etc
 help / color / mirror / code / Atom feed
* [PATCH] http_put: gracefully handle path allocation errors
@ 2016-06-01 22:32 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-06-01 22:32 UTC (permalink / raw)
  To: cmogstored-public

Failing to allocate memory should be a temporary error and be
non-fatal.
---
 http_put.c | 13 +++++++++++--
 1 file 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) {
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-06-01 22:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-01 22:32 [PATCH] http_put: gracefully handle path allocation errors Eric Wong

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/cmogstored.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).