File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
components/console/linenoise Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -979,6 +979,9 @@ static void sanitize(char* src) {
979
979
char * linenoise (const char * prompt ) {
980
980
char * buf = calloc (1 , LINENOISE_MAX_LINE );
981
981
int count = 0 ;
982
+ if (buf == NULL ) {
983
+ return NULL ;
984
+ }
982
985
if (!dumbmode ) {
983
986
count = linenoiseRaw (buf , LINENOISE_MAX_LINE , prompt );
984
987
} else {
@@ -1105,9 +1108,15 @@ int linenoiseHistorySave(const char *filename) {
1105
1108
* on error -1 is returned. */
1106
1109
int linenoiseHistoryLoad (const char * filename ) {
1107
1110
FILE * fp = fopen (filename ,"r" );
1108
- char buf [LINENOISE_MAX_LINE ];
1111
+ if (fp == NULL ) {
1112
+ return -1 ;
1113
+ }
1109
1114
1110
- if (fp == NULL ) return -1 ;
1115
+ char * buf = calloc (1 , LINENOISE_MAX_LINE );
1116
+ if (buf == NULL ) {
1117
+ fclose (fp );
1118
+ return -1 ;
1119
+ }
1111
1120
1112
1121
while (fgets (buf ,LINENOISE_MAX_LINE ,fp ) != NULL ) {
1113
1122
char * p ;
@@ -1117,6 +1126,9 @@ int linenoiseHistoryLoad(const char *filename) {
1117
1126
if (p ) * p = '\0' ;
1118
1127
linenoiseHistoryAdd (buf );
1119
1128
}
1129
+
1130
+ free (buf );
1120
1131
fclose (fp );
1132
+
1121
1133
return 0 ;
1122
1134
}
You can’t perform that action at this time.
0 commit comments