From: Christian Ehrhardt Date: Tue, 3 Mar 2015 11:44:46 +0000 (+0100) Subject: fio: fix smalloc strdop allocation failure X-Git-Tag: fio-2.2.7~25 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=2894a2d44cfa29c250276853e460b7fb5ea1ef7e;hp=f52c9691bc8c285f3445235c69acdfd6de7f9b82 fio: fix smalloc strdop allocation failure 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. Signed-off-by: Christian Ehrhardt Signed-off-by: Jens Axboe --- diff --git a/smalloc.c b/smalloc.c index 67cb7cc1..66f9ec0d 100644 --- a/smalloc.c +++ b/smalloc.c @@ -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; }