Skip to contentSkip to conversation

fio: fix smalloc strdop allocation failure

PATCH Applied Christian Ehrhardt 2 participants 2 messages Mar 3, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fio: fix smalloc strdop allocation failure

From: Christian Ehrhardt <[email protected]>

smalloc_strdup didn't check for allocation success and thereby ran into segfaults if the single pool went out of memory.
Now with this patch applied it is still failing, but in a more consistent way than segfaulting.

You still get a bad allocation, but it looks like this now:
fio: smalloc OOM
fio: filesetup.c:1495: dup_files: Assertion `0' failed. Aborted

In fact the upper layers expected smalloc_strdup to retrun NULL on failure.

---

[diffstat]

 smalloc.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

[diff]

---
 smalloc.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
smalloc.c +3 -2
@@ -492,9 +492,10 @@ void *scalloc(size_t nmemb, size_t size)
 
 char *smalloc_strdup(const char *str)
 {
-	char *ptr;
+	char *ptr = NULL;
 
 	ptr = smalloc(strlen(str) + 1);
-	strcpy(ptr, str);
+	if (ptr)
+		strcpy(ptr, str);
 	return ptr;
 }
Applied
#1 lore raw
Quoted 7 lines · Christian Ehrhardt

From: Christian Ehrhardt <[email protected]>

smalloc_strdup didn't check for allocation success and thereby ran into segfaults if the single pool went out of memory.
Now with this patch applied it is still failing, but in a more consistent way than segfaulting.

Quoted 8 lines

You still get a bad allocation, but it looks like this now:
fio: smalloc OOM
fio: filesetup.c:1495: dup_files: Assertion `0' failed. Aborted

In fact the upper layers expected smalloc_strdup to retrun NULL on failure.

Applied, thanks.

Signature · 1 line
Jens Axboe