diff --git a/src/lib/shell/MainLoopDefault.cpp b/src/lib/shell/MainLoopDefault.cpp index 6a3a6b300b53f3..30e748836b473c 100644 --- a/src/lib/shell/MainLoopDefault.cpp +++ b/src/lib/shell/MainLoopDefault.cpp @@ -57,6 +57,15 @@ size_t ReadLine(char * buffer, size_t max) break; } + // Stop the loop if the input stream is closed. + if (ret == 0) + { + if (line_sz > 0) + // Return current buffer if it is not empty. + buffer[line_sz++] = '\0'; + break; + } + if (ret != 1) continue;