C++ — неинициализированное значение было создано путем выделения кучи — Valgrind [закрыто]C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 C++ — неинициализированное значение было создано путем выделения кучи — Valgrind [закрыто]

Сообщение Anonymous »

У меня есть график, представляющий топологию сети. Впервые проблема была обнаружена в более крупной топологии. Теперь я могу воспроизвести ее в минимально возможной топологии, в которой есть два узла и связь, соединяющая их.
Ниже приведена функция для создания объекта графа.< /p>
graph_t *standalone_node_topology(void) {

graph_t *topo = create_new_graph("StandAlone Topo");
node_t *R0 = create_graph_node(topo, (const c_string)"R0");
node_t *R1 = create_graph_node(topo, (const c_string)"R1");
insert_link_between_two_nodes(R0, R1, "eth0", "eth0", 10);
return topo;
}

В fn, Insert_link_between_two_nodes ( ) я также создаю два объекта Interface, которые представляют интерфейс сетевых узлов.
void
insert_link_between_two_nodes(node_t *node1,
node_t *node2,
const char *from_if_name,
const char *to_if_name,
unsigned int cost){

linkage_t *link = new linkage_t;
link->Intf1 = std::make_shared
(from_if_name, INTF_TYPE_PHY, nullptr);
link->Intf1->SetSharedPtr(link->Intf1);
link->Intf2 = std::make_shared(to_if_name, INTF_TYPE_PHY, nullptr);
link->Intf2->SetSharedPtr(link->Intf2);

. . .
}

Проблема возникает, когда я создаю экземпляры объектов PhysicalInterface, как указано выше.
PhysicalInterface — производный класс, который наследует интерфейс базового класса.
Моя программа аварийно завершает работу через некоторое время работы. Когда я запускаю valgrind, я вижу проблему с конструкторами класса Interface.
Вставка обратной трассировки Valgrind ниже.
Я не понимаю, что вызывает неинициализированное значение. созданный путем выделения кучи. Я позаботился о том, чтобы инициализировать все переменные экземпляров классов. Вероятно, именно это неинициализированное значение приводит к сбою моей программы.
Сбой BT также отображается в верхней части Valgrind, он выходит из строя при печати имени интерфейса. «cprintf» — это мой настроенный printf, но он также дает сбой при использовании glibc printf.
==906547== Thread 6:
==906547== Use of uninitialised value of size 8
==906547== at 0x488DCE0: __GI_strlen (in /usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so)
==906547== by 0x4D09423: __printf_buffer (vfprintf-process-arg.c:435)
==906547== by 0x4D29DA3: __vsnprintf_internal (vsnprintf.c:96)
==906547== by 0x4D29DA3: vsnprintf (vsnprintf.c:103)
==906547== by 0x160713: cprintf(char const*, ...) (filters.cpp:153)
==906547== by 0x11722F: dump_interface_stats(Interface*) (net.c:182)
==906547== by 0x117287: dump_node_interface_stats(node_*) (net.c:196)
==906547== by 0x131CBB: show_interface_handler(int, stack*, op_mode) (nwcli.c:672)
==906547== by 0x1154CF: task_cbk_handler_internal(event_dispatcher_*, void*, unsigned int) (cli_interface.c:46)
==906547== by 0x13F94B: event_dispatcher_thread(void*) (event_dispatcher.c:222)
==906547== by 0x4D3597B: start_thread (pthread_create.c:447)
==906547== by 0x4D9B7DB: thread_start (clone.S:79)
==906547== Uninitialised value was created by a heap allocation
==906547== at 0x48859FC: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-arm64-linux.so)
==906547== by 0x114DD3: std::__new_allocator >::allocate(unsigned long, void const*) (new_allocator.h:151)
==906547== by 0x114A87: allocate (alloc_traits.h:482)
==906547== by 0x114A87: std::__allocated_ptr std::__allocate_guarded(std::allocator&) (allocated_ptr.h:98)
==906547== by 0x11474B: std::__shared_count::__shared_count(PhysicalInterface*&, std::_Sp_alloc_shared_tag, char const*&, InterfaceType_t&&, decltype(nullptr)&&) (shared_ptr_base.h:969)
==906547== by 0x1144CF: std::__shared_ptr::__shared_ptr(std::_Sp_alloc_shared_tag, char const*&, InterfaceType_t&&, decltype(nullptr)&&) (shared_ptr_base.h:1712)
==906547== by 0x1141FF: std::shared_ptr::shared_ptr(std::_Sp_alloc_shared_tag, char const*&, InterfaceType_t&&, decltype(nullptr)&&) (shared_ptr.h:464)
==906547== by 0x113C0B: std::shared_ptr::type> std::make_shared(char const*&, InterfaceType_t&&, decltype(nullptr)&&) (shared_ptr.h:1010)
==906547== by 0x112CB3: insert_link_between_two_nodes(node_*, node_*, char const*, char const*, unsigned int) (graph.c:58)
==906547== by 0x11588B: standalone_node_topology() (topologies.c:57)
==906547== by 0x10DE23: main (main.c:100)

Вставка полного кода конструкторов интерфейса как производного класса, так и базового класса:
Базовый класс:
Interface::Interface(std::string if_name, InterfaceType_t iftype)
{
this->if_name = std::move(if_name);
this->iftype = iftype;
this->att_node = NULL;
memset(&this->log_info, 0, sizeof(this->log_info));
this->link = NULL;
this->is_up = true;
this->ifindex = get_new_ifindex();
this->cost = INTF_METRIC_DEFAULT;

this->pkt_recv = 0;
this->pkt_sent = 0;
this->xmit_pkt_dropped = 0;
this->recvd_pkt_dropped = 0;

this->l2_egress_acc_lst = NULL;
this->l2_ingress_acc_lst = NULL;

this->l3_ingress_acc_lst2 = NULL;
this->l3_egress_acc_lst2 = NULL;

this->isis_intf_info = NULL;
this->intfP.reset();
}

Производный класс:
PhysicalInterface::PhysicalInterface(std::string ifname, InterfaceType_t iftype, mac_addr_t *mac_add)
: Interface(ifname, iftype)
{

this->switchport = false;

memset (this->mac_add.mac, 0, sizeof(this->mac_add.mac));

if (mac_add)
{
memcpy(this->mac_add.mac, mac_add->mac, sizeof(*mac_add));
}
this->l2_mode = LAN_MODE_NONE;
this->ip_addr = 0;
this->mask = 0;
this->used_as_underlying_tunnel_intf = 0;
this->trans_svc = NULL;
this->access_vlan_intf = nullptr;
}

class Interface {

private:
std::weak_ptr intfP;

protected:

Interface(std::string if_name, InterfaceType_t iftype);
public:
InterfaceType_t iftype;
std::string if_name;
node_t *att_node;
log_t log_info;
linkage_t *link;

/* L1 Properties of Interface */
bool is_up;
uint32_t ifindex;
uint32_t pkt_recv;
uint32_t pkt_sent;
uint32_t xmit_pkt_dropped;
uint32_t recvd_pkt_dropped;
uint32_t cost;

/* L2 Properties : Ingress & egress L2 Access_list */
access_list_t *l2_ingress_acc_lst;
access_list_t *l2_egress_acc_lst;

/* L3 properties : Ingress & egress L3 Access_list */
std::atomic l3_ingress_acc_lst2;
std::atomic l3_egress_acc_lst2;

/* L5 protocols */
isis_intf_info_t *isis_intf_info;

. ..
instance methods ...

}

class PhysicalInterface : public Interface {

private:
/* L2 Properties */
bool switchport;
mac_addr_t mac_add;
IntfL2Mode l2_mode;

/* L3 properties */
uint32_t ip_addr;
uint8_t mask;

protected:
public:
uint16_t used_as_underlying_tunnel_intf;

/* Below two are mutually exclusive */
TransportService *trans_svc;
VlanInterfaceP access_vlan_intf;

PhysicalInterface(std::string ifname, InterfaceType_t iftype, mac_addr_t *mac_add);
virtual ~PhysicalInterface();
. . .
other instance methods ....
}


Подробнее здесь: https://stackoverflow.com/questions/792 ... n-valgrind
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»