Bug 108117 - ncurses sigabrt's in delscreen() because of free() of already free'd memory
Summary: ncurses sigabrt's in delscreen() because of free() of already free'd memory
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 6.1-RELEASE
Hardware: Any Any
: Normal Affects Only Me
Assignee: Rong-En Fan
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-01-19 14:00 UTC by Allan Kintigh
Modified: 2007-04-24 10:46 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Allan Kintigh 2007-01-19 14:00:38 UTC
ncurses as distributed on 6.1-RELEASE and 6.2-RELEASE system has a
free() of already free'd memory in the delscreen() function causing an
error message to be sent to stderr and if running as root causes a
sigabrt to be sent to the process.

Fix: 

The ncurses port fixes the issue, but the released system code should probably be fixed.
How-To-Repeat: #include <time.h>
#include <curses.h>

/*
 * cc -o nc_test -lncurses ncurses.c
 */

int current_getch;
int doloop = 1;
static SCREEN *s;
static WINDOW *screen;

int now_sec, now_min, now_hour, now_day, now_wday, now_month, now_year;
time_t now;
struct tm *now_tm;

void screen_init(void) {
   s = newterm("vt100", stdout, stdin);
   set_term (s);
   noecho();
   cbreak();
   halfdelay(1);
   refresh(); // 1)
   screen = newwin(13, 27, 1, 1);
   box(screen, ACS_VLINE, ACS_HLINE);
}

static void update_display(void) {
   curs_set(0);
   mvwprintw(screen,1,1,"-------- HEADER --------");
   mvwprintw(screen,3,6,"TIME: %d:%d:%d", now_hour, now_min, now_sec);
   mvwprintw(screen,5,6,"DATE: %d-%d-%d", now_day, now_month, now_year);
   mvwprintw(screen,7,6,"PRESS q TO END");
   mvwprintw(screen,10,1,"-------- FOOTER --------");
   wrefresh(screen);
   refresh();
}

void screen_end(void) {
   delwin(screen);
   endwin();
   delscreen(s);
}

void maketime(void) {
        // Get the current date/time
        now = time (NULL);
        now_tm = localtime (&now);
        now_sec = now_tm->tm_sec;
        now_min = now_tm->tm_min;
        now_hour = now_tm->tm_hour;
        now_day = now_tm->tm_mday;
        now_wday = now_tm->tm_wday;
        now_month = now_tm->tm_mon + 1;
        now_year = now_tm->tm_year + 1900;
}

int main(void) {
   screen_init();
   while (doloop) {
      current_getch = getch();
      if (current_getch == 113) {
         doloop = 0;
      }
      maketime();
      update_display();
      sleep(1);
   }
   screen_end();
   printf("TEST ENDS\n");
   return 0;
}
Comment 1 Craig Rodrigues freebsd_committer freebsd_triage 2007-01-20 18:10:46 UTC
Responsible Changed
From-To: freebsd-bugs->rafan

rafan just updated ncurses in FreeBSD.
Comment 2 Rong-En Fan freebsd_committer freebsd_triage 2007-01-21 09:21:19 UTC
State Changed
From-To: open->feedback

Could you please try a recent current, which includes 
ncurses 5.6 in the base.
Comment 3 Mark Linimon freebsd_committer freebsd_triage 2007-04-24 10:45:09 UTC
State Changed
From-To: feedback->closed

Feedback timeout (3 months). 

If this is still a problem, please let us know and we can reopen it.