From a753da93e944d1c9d01f56020fa4833d34f80985 Mon Sep 17 00:00:00 2001 From: mlichvar Date: Tue, 15 May 2007 10:38:09 +0000 Subject: [PATCH] - free helplines and windows in newtFinished, check for overflow (#239992) --- newt.c | 33 ++++++++++++++++++++++++++++----- newt.spec | 1 + 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/newt.c b/newt.c index 8b20dab..d4bd778 100644 --- a/newt.c +++ b/newt.c @@ -321,6 +321,20 @@ int newtInit(void) { * @returns int , 0. (no errors reported) */ int newtFinished(void) { + if (currentWindow) { + for (; currentWindow >= windowStack; currentWindow--) { + free(currentWindow->buffer); + free(currentWindow->title); + } + currentWindow = NULL; + } + + if (currentHelpline) { + for (; currentHelpline >= helplineStack; currentHelpline--) + free(*currentHelpline); + currentHelpline = NULL; + } + SLsmg_gotorc(SLtt_Screen_Rows - 1, 0); newtCursorOn(); SLsmg_refresh(); @@ -622,7 +636,7 @@ void newtClearKeyBuffer(void) { * @param width unsigned int * @param height unsigned int * @param title - title string - * @return zero on success (currently no errors reported) + * @return zero on success */ int newtOpenWindow(int left, int top, unsigned int width, unsigned int height, @@ -633,6 +647,10 @@ int newtOpenWindow(int left, int top, newtFlushInput(); + if (currentWindow && currentWindow - windowStack + 1 + >= sizeof (windowStack) / sizeof (struct Window)) + return 1; + if (!currentWindow) { currentWindow = windowStack; } else { @@ -711,7 +729,7 @@ int newtOpenWindow(int left, int top, * @param width - width in char cells * @param height - no. of char cells. * @param title - fixed title - * @returns 0. No errors reported + * @returns zero on success */ int newtCenteredWindow(unsigned int width,unsigned int height, const char * title) { @@ -724,9 +742,7 @@ int newtCenteredWindow(unsigned int width,unsigned int height, left = (int)(SLtt_Screen_Cols - width) / 2; - newtOpenWindow(left, top, width, height, title); - - return 0; + return newtOpenWindow(left, top, width, height, title); } /** @@ -741,6 +757,9 @@ void newtPopWindowNoRefresh(void) { int j, row, col; int n = 0; + if (currentWindow == NULL) + return; + row = col = 0; row = currentWindow->top - 1; @@ -907,6 +926,10 @@ void newtRedrawHelpLine(void) { } void newtPushHelpLine(const char * text) { + if (currentHelpline && currentHelpline - helplineStack + 1 + >= sizeof (helplineStack) / sizeof (char *)) + return; + if (!text) text = defaultHelpLine; diff --git a/newt.spec b/newt.spec index af7a792..ca10eec 100644 --- a/newt.spec +++ b/newt.spec @@ -88,6 +88,7 @@ rm -rf $RPM_BUILD_ROOT %{_libdir}/libnewt.a %changelog +- free helplines and windows in newtFinished, check for overflow (#239992) - add release to -devel and -static requires (#238784) - fix cursor positioning when setting entry or checkbox flags - fix counting of items in checkboxtree -- 2.47.2