소스 검색

[mucurses] Attempt to fix resource leaks

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 년 전
부모
커밋
2ae759219b
1개의 변경된 파일4개의 추가작업 그리고 6개의 파일을 삭제
  1. 4
    6
      src/hci/mucurses/windows.c

+ 4
- 6
src/hci/mucurses/windows.c 파일 보기

@@ -48,11 +48,11 @@ int delwin ( WINDOW *win ) {
48 48
 WINDOW *derwin ( WINDOW *parent, int nlines, int ncols,
49 49
 	     		  	 int begin_y, int begin_x ) {
50 50
 	WINDOW *child;
51
-	if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
52
-		return NULL;
53 51
 	if ( ( (unsigned)ncols > parent->width ) || 
54 52
 	     ( (unsigned)nlines > parent->height ) )
55 53
 		return NULL;
54
+	if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
55
+		return NULL;
56 56
 	child->ori_y = parent->ori_y + begin_y;
57 57
 	child->ori_x = parent->ori_x + begin_x;
58 58
 	child->height = nlines;
@@ -113,11 +113,11 @@ int mvwin ( WINDOW *win, int y, int x ) {
113 113
  */
114 114
 WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
115 115
 	WINDOW *win;
116
-	if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
117
-		return NULL;
118 116
 	if ( ( (unsigned)( begin_y + nlines ) > stdscr->height ) &&
119 117
 	     ( (unsigned)( begin_x + ncols ) > stdscr->width ) )
120 118
 		return NULL;
119
+	if ( ( win = malloc( sizeof(WINDOW) ) ) == NULL )
120
+		return NULL;
121 121
 	win->ori_y = begin_y;
122 122
 	win->ori_x = begin_x;
123 123
 	win->height = nlines;
@@ -140,8 +140,6 @@ WINDOW *newwin ( int nlines, int ncols, int begin_y, int begin_x ) {
140 140
 WINDOW *subwin ( WINDOW *parent, int nlines, int ncols,
141 141
 			         int begin_y, int begin_x ) {
142 142
 	WINDOW *child;
143
-	if ( ( child = malloc( sizeof( WINDOW ) ) ) == NULL )
144
-		return NULL;
145 143
 	child = newwin( nlines, ncols, begin_y, begin_x );
146 144
 	child->parent = parent;
147 145
 	child->scr = parent->scr;

Loading…
취소
저장