Skip to content

Commit

Permalink
C++ mm cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
svpcom committed Sep 20, 2024
1 parent 971f783 commit 7d53559
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ bdist: all_bin

check:
cppcheck --std=c++11 --library=std --library=posix --library=gnu --inline-suppr --template=gcc --enable=all --suppress=cstyleCast --suppress=missingOverride --suppress=missingIncludeSystem src/
make clean
make CFLAGS="-g -fsanitize=address -fno-omit-frame-pointer" LDFLAGS="-fsanitize=address -static-libasan" test
make clean

pylint:
pylint --disable=R,C wfb_ng/*.py
Expand Down
20 changes: 11 additions & 9 deletions src/rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,14 @@ void Aggregator::deinit_fec(void)

for(int ring_idx = 0; ring_idx < RX_RING_SIZE; ring_idx++)
{
delete rx_ring[ring_idx].fragment_map;
delete[] rx_ring[ring_idx].fragment_map;
rx_ring[ring_idx].fragment_map = NULL;
for(int i=0; i < fec_n; i++)
{
delete rx_ring[ring_idx].fragments[i];
delete[] rx_ring[ring_idx].fragments[i];
}
delete rx_ring[ring_idx].fragments;
delete[] rx_ring[ring_idx].fragments;
rx_ring[ring_idx].fragments = NULL;
}

fec_free(fec_p);
Expand Down Expand Up @@ -851,12 +853,12 @@ void Aggregator::apply_fec(int ring_idx)
fec_decode(fec_p, (const uint8_t**)in_blocks, out_blocks, index, MAX_FEC_PAYLOAD);
}

void radio_loop(int argc, char* const *argv, int optind, uint32_t channel_id, shared_ptr<BaseAggregator> agg, int log_interval, int rcv_buf_size)
void radio_loop(int argc, char* const *argv, int optind, uint32_t channel_id, unique_ptr<BaseAggregator> &agg, int log_interval, int rcv_buf_size)
{
int nfds = argc - optind;
uint64_t log_send_ts = 0;
struct pollfd fds[MAX_RX_INTERFACES];
Receiver* rx[MAX_RX_INTERFACES];
unique_ptr<Receiver> rx[MAX_RX_INTERFACES];

if (nfds > MAX_RX_INTERFACES)
{
Expand All @@ -867,7 +869,7 @@ void radio_loop(int argc, char* const *argv, int optind, uint32_t channel_id, sh

for(int i = 0; i < nfds; i++)
{
rx[i] = new Receiver(argv[optind + i], i, channel_id, agg.get(), rcv_buf_size);
rx[i].reset(new Receiver(argv[optind + i], i, channel_id, agg.get(), rcv_buf_size));
fds[i].fd = rx[i]->getfd();
fds[i].events = POLLIN;
}
Expand Down Expand Up @@ -1073,11 +1075,11 @@ int main(int argc, char* const *argv)
{
if (optind >= argc) goto show_usage;

shared_ptr<BaseAggregator> agg;
unique_ptr<BaseAggregator> agg;
if(rx_mode == LOCAL){
agg = shared_ptr<Aggregator>(new Aggregator(client_addr, client_port, keypair, epoch, channel_id));
agg = unique_ptr<Aggregator>(new Aggregator(client_addr, client_port, keypair, epoch, channel_id));
}else{
agg = shared_ptr<Forwarder>(new Forwarder(client_addr, client_port));
agg = unique_ptr<Forwarder>(new Forwarder(client_addr, client_port));
}

radio_loop(argc, argv, optind, channel_id, agg, log_interval, rcv_buf);
Expand Down
16 changes: 8 additions & 8 deletions src/tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ void Transmitter::deinit_session(void)
{
for(int i=0; i < fec_n; i++)
{
delete block[i];
delete[] block[i];
}

delete block;
delete[] block;
fec_free(fec_p);

block = NULL;
Expand Down Expand Up @@ -659,7 +659,7 @@ uint32_t extract_rxq_overflow(struct msghdr *msg)
return 0;
}

void data_source(shared_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd, int fec_timeout, bool mirror, int log_interval)
void data_source(unique_ptr<Transmitter> &t, vector<int> &rx_fd, int control_fd, int fec_timeout, bool mirror, int log_interval)
{
int nfds = rx_fd.size();
assert(nfds > 0);
Expand Down Expand Up @@ -1338,7 +1338,7 @@ void local_loop(int argc, char* const* argv, int optind, int srv_port, int rcv_b
vector<int> rx_fd;
vector<string> wlans;
vector<tags_item_t> tags;
shared_ptr<Transmitter> t;
unique_ptr<Transmitter> t;

for(int i = 0; optind + i < argc; i++)
{
Expand Down Expand Up @@ -1371,12 +1371,12 @@ void local_loop(int argc, char* const* argv, int optind, int srv_port, int rcv_b
if (debug_port)
{
fprintf(stderr, "Using %zu ports from %d for wlan emulation\n", wlans.size(), debug_port);
t = shared_ptr<UdpTransmitter>(new UdpTransmitter(k, n, keypair, "127.0.0.1", debug_port, epoch, channel_id,
t = unique_ptr<UdpTransmitter>(new UdpTransmitter(k, n, keypair, "127.0.0.1", debug_port, epoch, channel_id,
fec_delay, tags, use_qdisc, fwmark));
}
else
{
t = shared_ptr<RawSocketTransmitter>(new RawSocketTransmitter(k, n, keypair, epoch, channel_id, fec_delay, tags,
t = unique_ptr<RawSocketTransmitter>(new RawSocketTransmitter(k, n, keypair, epoch, channel_id, fec_delay, tags,
wlans, radiotap_header, frame_type, use_qdisc, fwmark));
}

Expand Down Expand Up @@ -1450,8 +1450,8 @@ void distributor_loop(int argc, char* const* argv, int optind, int srv_port, int
}

vector<tags_item_t> tags;
shared_ptr<Transmitter> t = shared_ptr<RemoteTransmitter>(new RemoteTransmitter(k, n, keypair, epoch, channel_id, fec_delay, tags,
remote_hosts, radiotap_header, frame_type, use_qdisc, fwmark));
unique_ptr<Transmitter> t = unique_ptr<RemoteTransmitter>(new RemoteTransmitter(k, n, keypair, epoch, channel_id, fec_delay, tags,
remote_hosts, radiotap_header, frame_type, use_qdisc, fwmark));

int control_fd = open_control_fd(control_port);
data_source(t, rx_fd, control_fd, fec_timeout, mirror, log_interval);
Expand Down

0 comments on commit 7d53559

Please sign in to comment.