vma/dev: Fix new/delete size mismatch.#1149
vma/dev: Fix new/delete size mismatch.#1149strike-kokhotnikov wants to merge 1 commit intoMellanox:masterfrom
Conversation
Greptile OverviewGreptile SummaryFixed new/delete size mismatch by implementing custom allocation strategy using Key Changes
RationaleThe structures ( Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant UC as rfs_uc/rfs_mc
participant RFS as rfs (base)
participant NM as new_malloc<T>
participant AA as aligned_alloc
participant PN as placement new
participant D as ~rfs destructor
Note over UC,D: Allocation Flow
UC->>NM: new_malloc<attach_flow_data_*_t>(qp_mgr)
NM->>NM: static_assert(is_trivially_destructible)
NM->>AA: aligned_alloc(alignof(T), sizeof(T))
alt allocation fails
AA-->>NM: NULL
NM->>NM: throw std::bad_alloc
else allocation succeeds
AA-->>NM: aligned memory pointer
NM->>PN: new(p) T(args...)
PN-->>NM: constructed object
NM-->>UC: return T*
end
UC->>RFS: add to m_attach_flow_data_vector
Note over UC,D: Deallocation Flow
D->>D: iterate m_attach_flow_data_vector
D->>D: free(pointer)
Note over D: Uses free() not delete<br/>to match aligned_alloc
|
| template <class T, typename ...Args> | ||
| T * new_malloc(Args ... args) { | ||
| static_assert(std::is_trivially_destructible<T>::value == true); | ||
| void * p = aligned_alloc(alignof(T), sizeof(T)); |
There was a problem hiding this comment.
logic: aligned_alloc returns NULL on failure, but there's no null check before placement new
| void * p = aligned_alloc(alignof(T), sizeof(T)); | |
| void * p = aligned_alloc(alignof(T), sizeof(T)); | |
| if (!p) return NULL; | |
| return new(p) T(args...); |
|
Can one of the admins verify this patch? |
5ec33b3 to
b04c1ed
Compare
| attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v1_t>(p_ring->m_p_qp_mgr); | ||
| ibv_flow_spec_ib_set_by_dst_qpn(&(attach_flow_data_ib_v1->ibv_flow_attr.ib), |
There was a problem hiding this comment.
logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 63 causes crash
| attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v1_t>(p_ring->m_p_qp_mgr); | |
| ibv_flow_spec_ib_set_by_dst_qpn(&(attach_flow_data_ib_v1->ibv_flow_attr.ib), | |
| attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v1_t>(p_ring->m_p_qp_mgr); | |
| if (!attach_flow_data_ib_v1) return false; | |
| ibv_flow_spec_ib_set_by_dst_qpn(&(attach_flow_data_ib_v1->ibv_flow_attr.ib), |
| attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v2_t>(p_ring->m_p_qp_mgr); | ||
|
|
||
| p_ipv4 = &(attach_flow_data_ib_v2->ibv_flow_attr.ipv4); |
There was a problem hiding this comment.
logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 73 causes crash
| attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v2_t>(p_ring->m_p_qp_mgr); | |
| p_ipv4 = &(attach_flow_data_ib_v2->ibv_flow_attr.ipv4); | |
| attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_ipv4_tcp_udp_v2_t>(p_ring->m_p_qp_mgr); | |
| if (!attach_flow_data_ib_v2) return false; | |
| p_ipv4 = &(attach_flow_data_ib_v2->ibv_flow_attr.ipv4); |
| attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr); | ||
|
|
||
| ibv_flow_spec_eth_set(&(attach_flow_data_eth->ibv_flow_attr.eth), |
There was a problem hiding this comment.
logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 82 causes crash
| attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr); | |
| ibv_flow_spec_eth_set(&(attach_flow_data_eth->ibv_flow_attr.eth), | |
| attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr); | |
| if (!attach_flow_data_eth) return false; | |
| ibv_flow_spec_eth_set(&(attach_flow_data_eth->ibv_flow_attr.eth), |
| attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_v1_t>(p_ring->m_p_qp_mgr); | ||
|
|
||
| uint8_t dst_gid[16]; |
There was a problem hiding this comment.
logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 61 causes crash
| attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_v1_t>(p_ring->m_p_qp_mgr); | |
| uint8_t dst_gid[16]; | |
| attach_flow_data_ib_v1 = new_malloc<attach_flow_data_ib_v1_t>(p_ring->m_p_qp_mgr); | |
| if (!attach_flow_data_ib_v1) return false; | |
| uint8_t dst_gid[16]; |
| attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_v2_t>(p_ring->m_p_qp_mgr); | ||
|
|
||
| ibv_flow_spec_ipv4_set(&(attach_flow_data_ib_v2->ibv_flow_attr.ipv4), |
There was a problem hiding this comment.
logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 75 causes crash
| attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_v2_t>(p_ring->m_p_qp_mgr); | |
| ibv_flow_spec_ipv4_set(&(attach_flow_data_ib_v2->ibv_flow_attr.ipv4), | |
| attach_flow_data_ib_v2 = new_malloc<attach_flow_data_ib_v2_t>(p_ring->m_p_qp_mgr); | |
| if (!attach_flow_data_ib_v2) return false; | |
| ibv_flow_spec_ipv4_set(&(attach_flow_data_ib_v2->ibv_flow_attr.ipv4), |
| attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr); | ||
|
|
||
| uint8_t dst_mac[6]; |
There was a problem hiding this comment.
logic: missing null check after allocation - if new_malloc fails and returns null, dereferencing on line 93 causes crash
| attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr); | |
| uint8_t dst_mac[6]; | |
| attach_flow_data_eth = new_malloc<attach_flow_data_eth_ipv4_tcp_udp_t>(p_ring->m_p_qp_mgr); | |
| if (!attach_flow_data_eth) return false; | |
| uint8_t dst_mac[6]; |
b04c1ed to
ec5e44a
Compare
Description
Trivial child class was created with
newoperator, butdeleteoperator were applied to base class instance. Changing the classes to non-trivial is impossible, because they used in external rdma-core library.What
Fix mismatch in size of
newanddeletestructure.Why ?
Fixed memory leak problem.
Change type
What kind of change does this PR introduce?
Check list