'android ServiceManger::addService behavior on same service name

void TestService::Init()
{
    printf("return %d\n", android::defaultServiceManager()->addService(android::String16(TestServiceName), this));
    printf("return %d\n", android::defaultServiceManager()->addService(android::String16(TestServiceName), this));
    android::ProcessState::self()->startThreadPool();

}

With this code I compiled to executable testService
Running testService & for the first time I received this result

return 0
return 0

Running testService & the second time I received the same result but the first run crash with free(): invalid pointer
Inspecting coredump file I got

#0  0xb6a8d4fc in raise () from crosstool/sysroots/armv7ahf-neon-oe-linux-gnueabi/lib/libc.so.6
#1  0xb6a8ec04 in abort () from crosstool/sysroots/armv7ahf-neon-oe-linux-gnueabi/lib/libc.so.6
#2  0xb6acaae8 in __libc_message () from crosstool/sysroots/armv7ahf-neon-oe-linux-gnueabi/lib/libc.so.6
#3  0xb6ad133c in malloc_printerr () from crosstool/sysroots/armv7ahf-neon-oe-linux-gnueabi/lib/libc.so.6
#4  0xb6ad38d8 in _int_free () from crosstool/sysroots/armv7ahf-neon-oe-linux-gnueabi/lib/libc.so.6
#5  0x7f619be4 in ?? ()

what has happened?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source