Skip to content

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

Closed
@mrengineer7777

Description

@mrengineer7777
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.

Activity

mrengineer7777

mrengineer7777 commented on Feb 20, 2023

@mrengineer7777
CollaboratorAuthor

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

mrengineer7777

mrengineer7777 commented on Feb 28, 2023

@mrengineer7777
CollaboratorAuthor

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mrengineer7777

        Issue actions

          Use new(std::nothrow) to prevent crashes · Issue #7849 · espressif/arduino-esp32