[x265] [PATCH] Memory Leak Fix: Part 3
Pavan Tarun Chakka Venkata
pavan.tarun at multicorewareinc.com
Thu Nov 21 10:11:19 UTC 2024
>From 2bc2629ee6bde6d1ffdcf4bb9fde192db3b829e4 Mon Sep 17 00:00:00 2001
From: Min Chen <chenm003 at 163.com>
Date: Mon, 11 Nov 2024 21:10:42 -0800
Subject: [PATCH] Memory Leak Fix: Part 3
---
source/encoder/api.cpp | 1 -
source/encoder/bitcost.cpp | 9 +--------
source/encoder/bitcost.h | 27 +++++++++++++++++++--------
3 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp
index 5b6e959c0..40a325334 100644
--- a/source/encoder/api.cpp
+++ b/source/encoder/api.cpp
@@ -993,7 +993,6 @@ void x265_free_analysis_data(x265_param *param,
x265_analysis_data* analysis)
void x265_cleanup(void)
{
- BitCost::destroy();
}
x265_picture *x265_picture_alloc()
diff --git a/source/encoder/bitcost.cpp b/source/encoder/bitcost.cpp
index 902417e62..a17c6dd68 100644
--- a/source/encoder/bitcost.cpp
+++ b/source/encoder/bitcost.cpp
@@ -84,14 +84,6 @@ void BitCost::setQP(unsigned int qp)
* Class static data and methods
*/
-uint16_t *BitCost::s_costs[BC_MAX_QP];
-
-uint16_t* BitCost::s_fpelMvCosts[BC_MAX_QP][4];
-
-float *BitCost::s_bitsizes;
-
-Lock BitCost::s_costCalcLock;
-
void BitCost::CalculateLogs()
{
if (!s_bitsizes)
@@ -111,6 +103,7 @@ void BitCost::CalculateLogs()
void BitCost::destroy()
{
+ ScopedLock s(s_costCalcLock);
for (int i = 0; i < BC_MAX_QP; i++)
{
if (s_costs[i])
diff --git a/source/encoder/bitcost.h b/source/encoder/bitcost.h
index 46b232b42..425631056 100644
--- a/source/encoder/bitcost.h
+++ b/source/encoder/bitcost.h
@@ -35,7 +35,18 @@ class BitCost
{
public:
- BitCost() : m_cost_mvx(0), m_cost_mvy(0), m_cost(0), m_mvp(0) {}
+ BitCost()
+ : m_cost_mvx(0)
+ , m_cost_mvy(0)
+ , m_cost(0)
+ , m_mvp(0)
+ , s_bitsizes(NULL)
+ {
+ memset(m_fpelMvCosts, 0, sizeof(m_fpelMvCosts));
+ memset(s_costs, 0, sizeof(s_costs));
+ memset(s_fpelMvCosts, 0, sizeof(s_fpelMvCosts));
+ }
+ ~BitCost() { destroy(); }
void setQP(unsigned int qp);
@@ -51,13 +62,13 @@ public:
s_bitsizes[mv.y - m_mvp.y] + 0.5f);
}
- static inline uint32_t bitcost(const MV& mv, const MV& mvp)
+ inline uint32_t bitcost(const MV& mv, const MV& mvp) const
{
return (uint32_t)(s_bitsizes[mv.x - mvp.x] +
s_bitsizes[mv.y - mvp.y] + 0.5f);
}
- static void destroy();
+ void destroy();
protected:
@@ -82,15 +93,15 @@ private:
enum { BC_MAX_QP = 82 };
- static float *s_bitsizes;
+ float *s_bitsizes;
- static uint16_t *s_costs[BC_MAX_QP];
+ uint16_t *s_costs[BC_MAX_QP];
- static uint16_t *s_fpelMvCosts[BC_MAX_QP][4];
+ uint16_t *s_fpelMvCosts[BC_MAX_QP][4];
- static Lock s_costCalcLock;
+ Lock s_costCalcLock;
- static void CalculateLogs();
+ void CalculateLogs();
};
}
--
2.41.0.windows.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/30d2956b/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-MEMORY-LEAK-FIX-8.patch
Type: application/octet-stream
Size: 2926 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20241121/30d2956b/attachment.obj>
More information about the x265-devel
mailing list