forked from jbagg/QtZeroConf
Android: Fix missing or corrupt service name
The publish service name and type are passed to startServicePublish() as char pointers. startServicePublish() calls runOnAndroidThread which asks the java code to run registerService(). If name and type are objects on the stack, they could get freed / deleted before the registerService() is run in the java thread which would cause registerService() to use deleted objects. Fix --> make permanent objects for name and type.
This commit is contained in:
@ -77,6 +77,8 @@ QZeroConfPrivate::~QZeroConfPrivate()
|
||||
void QZeroConfPrivate::startServicePublish(const char *name, const char *type, quint16 port)
|
||||
{
|
||||
QAndroidJniObject ref(nsdManager);
|
||||
publishName = name;
|
||||
publishType = type;
|
||||
QtAndroid::runOnAndroidThread([=](){
|
||||
QAndroidJniObject txtMap("java/util/HashMap");
|
||||
foreach (const QByteArray &key, txtRecords.keys()) {
|
||||
@ -86,8 +88,8 @@ void QZeroConfPrivate::startServicePublish(const char *name, const char *type, q
|
||||
}
|
||||
|
||||
ref.callMethod<void>("registerService", "(Ljava/lang/String;Ljava/lang/String;ILjava/util/Map;)V",
|
||||
QAndroidJniObject::fromString(QString(name)).object<jstring>(),
|
||||
QAndroidJniObject::fromString(QString(type)).object<jstring>(),
|
||||
QAndroidJniObject::fromString(publishName).object<jstring>(),
|
||||
QAndroidJniObject::fromString(publishType).object<jstring>(),
|
||||
port,
|
||||
txtMap.object());
|
||||
});
|
||||
|
@ -54,6 +54,8 @@ public:
|
||||
bool browserExists = false;
|
||||
bool publisherExists = false;
|
||||
QMap<QByteArray, QByteArray> txtRecords;
|
||||
QString publishName;
|
||||
QString publishType;
|
||||
|
||||
|
||||
private slots:
|
||||
|
Reference in New Issue
Block a user