I am trying to create a dbus proxy using a MyDBUS library I have been assigned
The problem is, when I try to do new MyDBUS()
the program stops and a malloc error comes out on the screen output, before eternally waiting for who knows what input
This is the first time I encounter a new operator failing to do a malloc, but from what I read it could be from heap corruption? It is also puzzling how the same code works at least half a dozen times throughout the project but not here.
As far as I know the new operator creates a new instance of the object so it shouldn’t be interferring with the other instances, even if inside the MyDBUS object I have several std::unique_ptr to various proxies and adaptors
MY CODE
int CreateDBusHandler( std::shared_ptr< MyDBUS > &dbusHandler )
{
std::cout << "Initializing dbusHandler and interfaces..." << std::endl;
try
{
// create local DbusHandler instance and connect it to event loops
std::cout << "PRE CREATE" << std::endl;
dbusHandler = MyDBUS::create();
std::cout << "POST CREATE" << std::endl;
}
catch ( ... )
{ /* ... */ }
std::cout << "End initializing dbusHandler and interfaces..." << std::endl;
return 0;
}
int main()
{
std::ios::sync_with_stdio( true );
system("echo STARTING DBUS HANDLER");
std::shared_ptr< MyDBUS > dbusHandler;
CreateDBusHandler( dbusHandler );
std::cout << "Hello world!" << std::endl;
return 0;
}
LIBRARY CODE (with added cout)
While on the MyDBUS library I have this static create function and the constructor it calls
static std::shared_ptr< MyDBUS > create()
{
std::cout << "CREATE FUNCTION START" << std::endl;
MyDBUS* tmpDbusHandlerPtr = new MyDBUS();
std::cout << "CREATE FUNCTION STOP" << std::endl;
std::cout << "CAST TO SHARED_PTR" << std::endl;
std::shared_ptr< MyDBUS > tmpShared = std::shared_ptr< MyDBUS >(tmpDbusHandlerPtr);
std::cout << "RETURN SHARED_PTR" << std::endl;
return tmpShared;
}
MyDBUS::MyDBUS()
{
std::cout << "PRE CREATE BUS CONNECTION" << std::endl;
seshConnect = sdbus::createSessionBusConnection();
sysConnect = sdbus::createSystemBusConnection();
std::cout << "POST CREATE BUS CONNECTION" << std::endl;
}
SCREEN OUTPUT
The compilation goes smoothly, but when I try to launch it I see the log
STARTING DBUS HANDLER
Initializing dbusHandler and interfaces...
PRE CREATE
CREATE FUNCTION START
malloc.c:2379: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
From the amount of logs shown, the program stops when it calls new MyDBUS()
. The most peculiar thing is it doesn’t crash but eternally remains there until I stop it.
Any idea?
TheHerborist is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.