Skip to content

Commit

Permalink
misc: fix memory leaks when creating new threads
Browse files Browse the repository at this point in the history
  • Loading branch information
jsm174 committed Feb 21, 2024
1 parent 13b0f52 commit c4ab92e
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/DMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void DMD::UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t h
dmdUpdate.b = b;
strcpy(dmdUpdate.name, name ? name : "");

new std::thread(
std::thread(
[this, dmdUpdate]()
{
std::unique_lock<std::shared_mutex> ul(m_dmdSharedMutex);
Expand All @@ -266,7 +266,8 @@ void DMD::UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t h

ul.unlock();
m_dmdCV.notify_all();
});
})
.detach();
}

void DMD::UpdateData(const uint8_t* pData, int depth, uint16_t width, uint16_t height, uint8_t r, uint8_t g, uint8_t b,
Expand Down Expand Up @@ -306,7 +307,7 @@ void DMD::UpdateRGB16Data(const uint16_t* pData, uint16_t width, uint16_t height
dmdUpdate.hasSegData2 = false;
strcpy(dmdUpdate.name, "");

new std::thread(
std::thread(
[this, dmdUpdate]()
{
std::unique_lock<std::shared_mutex> ul(m_dmdSharedMutex);
Expand All @@ -317,7 +318,8 @@ void DMD::UpdateRGB16Data(const uint16_t* pData, uint16_t width, uint16_t height

ul.unlock();
m_dmdCV.notify_all();
});
})
.detach();
}

void DMD::UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pData1, const uint16_t* pData2, uint8_t r,
Expand Down Expand Up @@ -353,7 +355,7 @@ void DMD::UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pDat
dmdUpdate.b = b;
strcpy(dmdUpdate.name, name ? name : "");

new std::thread(
std::thread(
[this, dmdUpdate]()
{
std::unique_lock<std::shared_mutex> ul(m_dmdSharedMutex);
Expand All @@ -364,7 +366,8 @@ void DMD::UpdateAlphaNumericData(AlphaNumericLayout layout, const uint16_t* pDat

ul.unlock();
m_dmdCV.notify_all();
});
})
.detach();
}

void DMD::FindDisplays()
Expand All @@ -373,7 +376,7 @@ void DMD::FindDisplays()

m_finding = true;

new std::thread(
std::thread(
[this]()
{
Config* const pConfig = Config::GetInstance();
Expand Down Expand Up @@ -424,7 +427,8 @@ void DMD::FindDisplays()
#endif

m_finding = false;
});
})
.detach();
}

void DMD::DmdFrameReadyResetThread()
Expand Down Expand Up @@ -644,7 +648,7 @@ void DMD::PixelcadeDMDThread()
for (int i = 0; i < length; i++)
{
int pos = i * 3;
uint32_t r = rgb24Data[pos];
uint32_t r = rgb24Data[pos ];
uint32_t g = rgb24Data[pos + 1];
uint32_t b = rgb24Data[pos + 2];

Expand Down Expand Up @@ -862,7 +866,7 @@ void DMD::RGB24DMDThread()
{
int palettePos = renderBuffer[i] * 3;
int pos = i * 3;
rgb24Data[pos ] = palette[palettePos];
rgb24Data[pos] = palette[palettePos];
rgb24Data[pos + 1] = palette[palettePos + 1];
rgb24Data[pos + 2] = palette[palettePos + 2];
}
Expand Down Expand Up @@ -921,7 +925,7 @@ bool DMD::UpdatePalette(uint8_t* pPalette, uint8_t depth, uint8_t r, uint8_t g,
uint8_t palette[192];

const uint8_t colors = (depth == 2) ? 4 : 16;
memcpy(palette, pPalette, colors*3);
memcpy(palette, pPalette, colors * 3);
uint8_t pos = 0;

for (uint8_t i = 0; i < colors; i++)
Expand All @@ -932,7 +936,7 @@ bool DMD::UpdatePalette(uint8_t* pPalette, uint8_t depth, uint8_t r, uint8_t g,
pPalette[pos++] = (uint8_t)((float)b * perc);
}

return (memcmp(pPalette, palette, colors*3) != 0);
return (memcmp(pPalette, palette, colors * 3) != 0);
}

void DMD::AdjustRGB24Depth(uint8_t* pData, uint8_t* pDstData, int length, uint8_t* palette, uint8_t depth)
Expand Down Expand Up @@ -963,7 +967,7 @@ void DMD::AdjustRGB24Depth(uint8_t* pData, uint8_t* pDstData, int length, uint8_
}
else
{
memcpy(pDstData, pData, length*3);
memcpy(pDstData, pData, length * 3);
}
}

Expand Down

1 comment on commit c4ab92e

@jsm174
Copy link
Collaborator Author

@jsm174 jsm174 commented on c4ab92e Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toxieinc, @mkalkbrenner

hopefully this should take care of:

Screenshot 2024-02-20 at 10 09 58 PM

Please sign in to comment.