File tree Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Expand file tree Collapse file tree 1 file changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -297,11 +297,20 @@ static char *emptyprompt = "";
297297
298298PRIM (readline ) {
299299 char * line ;
300- /* TODO: estrdup? */
301- char * prompt = ( list == NULL ? emptyprompt : strdup ( getstr ( list -> term ))) ;
300+ char * pr0 = getstr ( list -> term );
301+ char * prompt = emptyprompt ;
302302 int old = dup (0 ), in = fdmap (0 );
303- if (dup2 (in , 0 ) == -1 )
303+
304+ if (list != NULL ) {
305+ size_t psize = strlen (pr0 ) * sizeof (char ) + 1 ;
306+ prompt = ealloc (psize );
307+ memcpy (prompt , pr0 , psize );
308+ }
309+ if (dup2 (in , 0 ) == -1 ) {
310+ if (prompt != emptyprompt )
311+ efree (prompt );
304312 fail ("$&readline" , "dup2: %s" , esstrerror (errno ));
313+ }
305314
306315 ExceptionHandler
307316
@@ -311,16 +320,16 @@ PRIM(readline) {
311320
312321 CatchException (e )
313322
314- mvfd (old , 0 );
315323 if (prompt != emptyprompt )
316324 efree (prompt );
325+ mvfd (old , 0 );
317326 throw (e );
318327
319328 EndExceptionHandler
320329
321- mvfd (old , 0 );
322330 if (prompt != emptyprompt )
323331 efree (prompt );
332+ mvfd (old , 0 );
324333
325334 if (line == NULL )
326335 return NULL ;
You can’t perform that action at this time.
0 commit comments