diff --git a/Contrib/System/Source/Plugin.c b/Contrib/System/Source/Plugin.c index 31744293..06595089 100644 --- a/Contrib/System/Source/Plugin.c +++ b/Contrib/System/Source/Plugin.c @@ -21,18 +21,14 @@ TCHAR *AllocStr(TCHAR *str) TCHAR* system_popstring() { - TCHAR *str; - stack_t *th; + stack_t *pSt; + TCHAR *src, *dst, *retval; - if (!g_stacktop || !*g_stacktop) return NULL; - th=(*g_stacktop); + if (!g_stacktop || !*g_stacktop) return NULL; + pSt = *g_stacktop, *g_stacktop = pSt->next, src = pSt->text, dst = (TCHAR*)pSt; - str = AllocString(); - lstrcpy(str,th->text); - - *g_stacktop = th->next; - GlobalFree((HGLOBAL)th); - return str; + // We don't have to call AllocString+lstrcpy+GlobalFree if we convert the stack item to a string + for (retval = dst;;) if (!(*dst++ = *src++)) return retval; } TCHAR *system_pushstring(TCHAR *str) diff --git a/Contrib/System/Source/System.c b/Contrib/System/Source/System.c index c2185b04..89a19544 100644 --- a/Contrib/System/Source/System.c +++ b/Contrib/System/Source/System.c @@ -164,6 +164,7 @@ PLUGINFUNCTION(Debug) CloseHandle(logfile); logfile = NULL; } + if (o1) GlobalFree(o1); } PLUGINFUNCTIONEND #else