diff --git a/adapter/uhdf2/host/devhost.c b/adapter/uhdf2/host/devhost.c index 0e782eda62c1743ba80dc90af9abd9a31bdbc879..48c7e2d086c4ebd7c374a435c7366c64b07baba2 100644 --- a/adapter/uhdf2/host/devhost.c +++ b/adapter/uhdf2/host/devhost.c @@ -157,6 +157,7 @@ static void SetHostProperties(int argc, char **argv, const char *hostName) } } +struct IDevHostService *g_instance = NULL; int main(int argc, char **argv) { if (argc < DEVHOST_MIN_INPUT_PARAM_NUM) { @@ -173,6 +174,7 @@ int main(int argc, char **argv) HDF_LOGI("hdf device host %{public}s %{public}d start", hostName, hostId); SetHostProperties(argc, argv, hostName); struct IDevHostService *instance = DevHostServiceNewInstance(hostId, hostName); + g_instance = instance; if (instance == NULL || instance->StartService == NULL) { HDF_LOGE("DevHostServiceGetInstance fail"); return HDF_ERR_INVALID_OBJECT; @@ -202,3 +204,10 @@ int main(int argc, char **argv) } return status; } + +__attribute__((destructor)) void ReleaseInstance() +{ + if (g_instance != NULL) { + DevHostServiceFreeInstance(g_instance); + } +}