If we're going to loop, pausing and then retrying malloc() after it
has failed, in the hope that some other thread has free'd some memory, but we want to bound the number of attempts, it helps if we actually count them - otherwise we never get nearer to the limit. In practice, malloc() for a reasonable application on a modern system almost never fails, so the code containing this bug has probably never been, and never will be, executed, but just in case, someday. For this, it isn't clear if the intent was to have 10 retries (ie: 11 attempts) or 10 tries, but as the code said "retries > 10", I am assuming the former (not that it matters, if the malloc() has failed 10 times in a row, with 10 second pauses between, the chances of an 11th succeeding aren't great).
This commit is contained in:
parent
15f8c76f05
commit
12f8bae508
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rumpuser_sp.c,v 1.74 2020/03/24 14:47:02 kamil Exp $ */
|
||||
/* $NetBSD: rumpuser_sp.c,v 1.75 2020/03/24 14:56:31 kre Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2010, 2011 Antti Kantee. All Rights Reserved.
|
||||
|
@ -37,7 +37,7 @@
|
|||
#include "rumpuser_port.h"
|
||||
|
||||
#if !defined(lint)
|
||||
__RCSID("$NetBSD: rumpuser_sp.c,v 1.74 2020/03/24 14:47:02 kamil Exp $");
|
||||
__RCSID("$NetBSD: rumpuser_sp.c,v 1.75 2020/03/24 14:56:31 kre Exp $");
|
||||
#endif /* !lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -912,7 +912,7 @@ schedulework(struct spclient *spc, enum sbatype sba_type)
|
|||
|
||||
reqno = spc->spc_hdr.rsp_reqno;
|
||||
while ((sba = malloc(sizeof(*sba))) == NULL) {
|
||||
if (nworker == 0 || retries > 10) {
|
||||
if (nworker == 0 || retries++ > 10) {
|
||||
send_error_resp(spc, reqno, RUMPSP_ERR_TRYAGAIN);
|
||||
spcfreebuf(spc);
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue