Opened 5 years ago

Closed 5 years ago

#14802 closed defect (fixed)

Return 0 when we fail to get the amount of system memory on some obscure OS

Reported by: sysrqb Owned by:
Priority: Medium Milestone: Tor: 0.2.6.x-final
Component: Core Tor/Tor Version: Tor: 0.2.5.4-alpha
Severity: Keywords:
Cc: Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

Currently we incorrectly return -1 when sysctl fails in

#elif defined(HAVE_SYSCTL) && defined(HW_PHYSMEM)
  /* On some systems (like FreeBSD I hope) you can use a size_t with
   * HW_PHYSMEM. */
  size_t memsize=0;
  size_t len = sizeof(memsize);
  int mib[2] = {CTL_HW, HW_USERMEM};
  if (sysctl(mib,2,&memsize,&len,NULL,0))
    return -1;

  return memsize;

Child Tickets

Change History (4)

comment:1 Changed 5 years ago by sysrqb

diff --git a/src/common/compat.c b/src/common/compat.c
index 5575316..fde65d9 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -3161,7 +3161,7 @@ get_total_system_memory_impl(void)
   size_t len = sizeof(memsize);
   int mib[2] = {CTL_HW, HW_USERMEM};
   if (sysctl(mib,2,&memsize,&len,NULL,0))
-    return -1;
+    return 0;
 
   return memsize;
 

Should do it.

Interestingly, I stumbled upon [0], which seems to be fairly comprehensive.

Something to think about.
[0] http://nadeausoftware.com/articles/2012/09/c_c_tip_how_get_physical_memory_size_system

comment:2 Changed 5 years ago by sysrqb

Status: newneeds_review

Pushed bug14802 and bug14802_025 to my public repo. bug fix on 0.2.5.4-alpha.

comment:3 Changed 5 years ago by nickm

Milestone: Tor: 0.2.5.x-final

Merged to master; considering for possible backport to 0.2.5

comment:4 Changed 5 years ago by nickm

Milestone: Tor: 0.2.5.x-finalTor: 0.2.6.x-final
Resolution: fixed
Status: needs_reviewclosed

Not backporting these.

Note: See TracTickets for help on using tickets.