Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: simplify memory management using node::Malloc() and friends #8482

Merged
merged 4 commits into from
Sep 29, 2016

Commits on Sep 29, 2016

  1. src: add Malloc() size param + overflow detection

    Adds an optional second parameter to `node::Malloc()` and
    an optional third parameter to `node::Realloc()` giving the
    size/number of items to be allocated, in the style of `calloc(3)`.
    
    Use a proper overflow check using division;
    the previous `CHECK_GE(n * size, n);` would not detect all cases
    of overflow (e.g. `size == SIZE_MAX / 2 && n == 3`).
    
    PR-URL: nodejs#8482
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
    Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
    addaleax committed Sep 29, 2016
    Configuration menu
    Copy the full SHA
    eb927fa View commit details
    Browse the repository at this point in the history
  2. src: pass desired return type to allocators

    Pass the desired return type directly to the allocation functions,
    so that the resulting `static_cast` from `void*` becomes unneccessary
    and the return type can be use as a reasonable default value for the
    `size` parameter.
    
    PR-URL: nodejs#8482
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
    Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
    addaleax committed Sep 29, 2016
    Configuration menu
    Copy the full SHA
    48ed654 View commit details
    Browse the repository at this point in the history
  3. src: provide allocation + nullptr check shortcuts

    Provide shortcut `node::CheckedMalloc()` and friends that
    replace `node::Malloc()` + `CHECK_NE(·, nullptr);` combinations
    in a few places.
    
    PR-URL: nodejs#8482
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
    Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
    addaleax committed Sep 29, 2016
    Configuration menu
    Copy the full SHA
    ea94086 View commit details
    Browse the repository at this point in the history
  4. src: notify V8 for low memory when alloc fails

    Call `v8::Isolate::GetCurrent()->LowMemoryNotification()` when
    an allocation fails to give V8 a chance to clean up and return
    memory before retrying (and possibly giving up).
    
    PR-URL: nodejs#8482
    Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
    Reviewed-By: James M Snell <jasnell@gmail.com>
    Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
    Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
    addaleax committed Sep 29, 2016
    Configuration menu
    Copy the full SHA
    72c60e8 View commit details
    Browse the repository at this point in the history