-
Notifications
You must be signed in to change notification settings - Fork 168
vma/dev: Fix new/delete size mismatch. #1149
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
vma/dev: Fix new/delete size mismatch. #1149
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 1 comment
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, 6 comments
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4 files reviewed, no comments
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