Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumpuser If we're going to loop, pausing and then ret...



details:   https://anonhg.NetBSD.org/src/rev/cfb6b7551e0f
branches:  trunk
changeset: 746215:cfb6b7551e0f
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Mar 24 14:56:31 2020 +0000

description:
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).

diffstat:

 lib/librumpuser/rumpuser_sp.c |  6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diffs (27 lines):

diff -r 8952275d888f -r cfb6b7551e0f lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c     Tue Mar 24 14:47:02 2020 +0000
+++ b/lib/librumpuser/rumpuser_sp.c     Tue Mar 24 14:56:31 2020 +0000
@@ -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 @@
 
        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;



Home | Main Index | Thread Index | Old Index