Skip to content

Use new(std::nothrow) to prevent crashes #7849

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

Closed
1 task done
mrengineer7777 opened this issue Feb 14, 2023 · 2 comments
Closed
1 task done

Use new(std::nothrow) to prevent crashes #7849

mrengineer7777 opened this issue Feb 14, 2023 · 2 comments
Labels
Status: Awaiting triage Issue is waiting for triage

Comments

@mrengineer7777
Copy link
Collaborator

Board

NA

Device Description

NA

Hardware Configuration

Arduino ESP32 Feather

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

Win11

Flash frequency

80Mhz

PSRAM enabled

no

Upload speed

115200

Description

I noticed in ESP8266 that they have changed their new calls to new(std::nothrow). This could prevent some crashes in our libraries.

See esp8266/Arduino@6925982

cbuf is one of the libraries that was fixed.

Sketch

#include "Arduino.h"
#include "cbuf.h"

void setup() {
    cbuf *p = new cbuf(128);
    p->resize(100);
}

void loop() {
}

Debug Message

Crash on low memory

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@mrengineer7777
Copy link
Collaborator Author

Draft PR opened. For the example cases corrected, it may make more sense to convert from new to malloc.

@mrengineer7777
Copy link
Collaborator Author

I have decided not to do this at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting triage Issue is waiting for triage
Projects
None yet
Development

No branches or pull requests

1 participant