Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(Wire): avoid memory leaks#2148

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fpistm merged 1 commit intostm32duino:mainfromfpistm:Wire_destructor
Oct 19, 2023
Merged

Conversation

fpistm
Copy link
Member

@fpistmfpistm commentedOct 19, 2023
edited
Loading

add destructor to call end().
Fixes#2142

Tested with this example:
#include<Wire.h>#include<malloc.h>extern"C"char *sbrk(int i);/* Use linker definition*/externchar _end;externchar _sdata;externchar _estack;externchar _Min_Stack_Size;staticchar *ramstart = &_sdata;staticchar *ramend = &_estack;staticchar *minSP = (char *)(ramend - &_Min_Stack_Size);voiddisplay_mallinfo(void) {char *heapend = (char *)sbrk(0);char *stack_ptr = (char *)__get_MSP();structmallinfo mi =mallinfo();  Serial.print("Total non-mmapped bytes (arena):");  Serial.println(mi.arena);  Serial.print("# of free chunks (ordblks):");  Serial.println(mi.ordblks);  Serial.print("# of free fastbin blocks (smblks):");  Serial.println(mi.smblks);  Serial.print("# of mapped regions (hblks):");  Serial.println(mi.hblks);  Serial.print("Bytes in mapped regions (hblkhd):");  Serial.println(mi.hblkhd);  Serial.print("Max. total allocated space (usmblks):");  Serial.println(mi.usmblks);  Serial.print("Free bytes held in fastbins (fsmblks):");  Serial.println(mi.fsmblks);  Serial.print("Total allocated space (uordblks):");  Serial.println(mi.uordblks);  Serial.print("Total free space (fordblks):");  Serial.println(mi.fordblks);  Serial.print("Topmost releasable block (keepcost):");  Serial.println(mi.keepcost);  Serial.print("RAM Start at:       0x");  Serial.println((unsignedlong)ramstart, HEX);  Serial.print("Data/Bss end at:    0x");  Serial.println((unsignedlong)&_end, HEX);  Serial.print("Heap end at:        0x");  Serial.println((unsignedlong)heapend, HEX);  Serial.print("Stack Ptr end at:   0x");  Serial.println((unsignedlong)stack_ptr, HEX);  Serial.print("RAM End at:         0x");  Serial.println((unsignedlong)ramend, HEX);  Serial.print("Heap RAM Used:");  Serial.println(mi.uordblks);  Serial.print("Program RAM Used:");  Serial.println(&_end - ramstart);  Serial.print("Stack RAM Used:");  Serial.println(ramend - stack_ptr);  Serial.print("Estimated Free RAM:");  Serial.println(((stack_ptr < minSP) ? stack_ptr : minSP) - heapend + mi.fordblks);}voidsetup() {// initialize serial communication at 115200 bits per second:  Serial.begin(115200);delay(1000);}#defineDATA_SIZE WIRE_MAX_TX_BUFF_LENGTHconstuint8_t data[DATA_SIZE] = {0xFF };voidloop() {  Serial.println("============== Before allocating blocks ==============");display_mallinfo();// Instantiate Wire  TwoWire Wire1 =TwoWire();  Wire1.begin();  Wire1.beginTransmission(0x38);  Wire1.write(data, DATA_SIZE);  Serial.println("============== After allocating blocks ==============");display_mallinfo();delay(1000);}

add destructor to call end().Fixesstm32duino#2142Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistmfpistm added the fix 🩹Bug fix labelOct 19, 2023
@fpistmfpistm added this to the2.7.0 milestoneOct 19, 2023
@fpistmfpistm merged commitff1731f intostm32duino:mainOct 19, 2023
@fpistmfpistm deleted the Wire_destructor branchOctober 19, 2023 14:57
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
fix 🩹Bug fix
Projects
Milestone
2.7.0
Development

Successfully merging this pull request may close these issues.

Possible memory leak in Wire.cpp
1 participant
@fpistm

[8]ページ先頭

©2009-2025 Movatter.jp