X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=service.cpp;h=617cad12dea70ee44df9c6096deee37764e30166;hb=f124b07b52a569dd9e332d0940af592d0e8e201d;hp=f575a37284941eb98f5389c5f82d3b86e47668d0;hpb=ac3246ff809b060c2be8e0c004e294f0d00e210d;p=nssm.git diff --git a/service.cpp b/service.cpp index f575a37..617cad1 100644 --- a/service.cpp +++ b/service.cpp @@ -275,8 +275,18 @@ static inline unsigned long throttle_milliseconds(unsigned long throttle) { void set_service_environment(nssm_service_t *service) { if (! service) return; - if (service->env) duplicate_environment(service->env); - if (service->env_extra) set_environment_block(service->env_extra); + + /* + We have to duplicate the block because this function will be called + multiple times between registry reads. + */ + if (service->env) duplicate_environment_strings(service->env); + if (! service->env_extra) return; + TCHAR *env_extra = copy_environment_block(service->env_extra); + if (! env_extra) return; + + set_environment_block(env_extra); + HeapFree(GetProcessHeap(), 0, env_extra); } void unset_service_environment(nssm_service_t *service) { @@ -1734,6 +1744,9 @@ int start_service(nssm_service_t *service) { return stop_service(service, 4, true, true); } + /* The pre-start hook will have cleaned the environment. */ + set_service_environment(service); + bool inherit_handles = false; if (si.dwFlags & STARTF_USESTDHANDLES) inherit_handles = true; unsigned long flags = service->priority & priority_mask();