diff --git a/C/flags.c b/C/flags.c index eb50a05c2..c6087f7d2 100644 --- a/C/flags.c +++ b/C/flags.c @@ -1341,6 +1341,7 @@ do_prolog_flag_property(Term tflag, Term modt = CurrentModule; tflag = Yap_YapStripModule(tflag, &modt); } else { + free(args); Yap_Error(TYPE_ERROR_ATOM, tflag, "yap_flag/2"); return (FALSE); } @@ -1397,6 +1398,7 @@ do_prolog_flag_property(Term tflag, } } // UNLOCK(GLOBAL_Prolog_Flag[sno].prolog_flaglock); + free(args); return rc; } @@ -1501,8 +1503,10 @@ static Int do_create_prolog_flag(USES_REGS1) { fv = GetFlagProp(AtomOfTerm(tflag)); if (fv) { if (args[PROLOG_FLAG_PROPERTY_KEEP].used && - args[PROLOG_FLAG_PROPERTY_KEEP].tvalue == TermTrue) + args[PROLOG_FLAG_PROPERTY_KEEP].tvalue == TermTrue) { + free(args); return true; + } } else { newFlag(tflag, tval); fv = GetFlagProp(AtomOfTerm(tflag)); @@ -1530,6 +1534,7 @@ static Int do_create_prolog_flag(USES_REGS1) { fv->type = isground; } break; case PROLOG_FLAG_PROPERTY_SCOPE: + free(args); return false; case PROLOG_FLAG_PROPERTY_END: break; @@ -1537,6 +1542,7 @@ static Int do_create_prolog_flag(USES_REGS1) { } } // UNLOCK(GLOBAL_Prolog_Flag[sno].prolog_flaglock); + free(args); return true; } diff --git a/os/console.c b/os/console.c index d0d9484df..a4f52fa76 100644 --- a/os/console.c +++ b/os/console.c @@ -138,7 +138,6 @@ restart: #endif LOCAL_PrologMode |= ConsoleGetcMode; ch = fgetc(s->file); - printf("got %d\n", ch); #if HAVE_SIGINTERRUPT siginterrupt(SIGINT, FALSE); #endif diff --git a/os/format.c b/os/format.c index 69a0aaae4..ce80e96ef 100644 --- a/os/format.c +++ b/os/format.c @@ -351,7 +351,7 @@ static bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS) { /* last gap??*/ if (padi-fg->gap == fg->gapi) { for (j=0; j < fill_space; j++) - f_putc(sno0, padi->filler); + f_putc(sno0, (padi-1)->filler); } } diff --git a/os/iopreds.c b/os/iopreds.c index afe74ccce..49090d878 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -1194,16 +1194,20 @@ do_open(Term file_name, Term t2, } /* done */ sno = GetFreeStreamD(); - if (sno < 0) + if (sno < 0) { + free(args); return PlIOError(RESOURCE_ERROR_MAX_STREAMS, TermNil, "open/3"); + } st = &GLOBAL_Stream[sno]; st->user_name = file_name; flags = s; // user requested encoding? if (args[OPEN_ALIAS].used) { Atom al = AtomOfTerm(args[OPEN_ALIAS].tvalue); - if (!Yap_AddAlias(al, sno)) + if (!Yap_AddAlias(al, sno)) { + free(args); return false; + } } if (args[OPEN_ENCODING].used) { tenc = args[OPEN_ENCODING].tvalue; @@ -1277,10 +1281,11 @@ do_open(Term file_name, Term t2, free((void *)fname); fname = LOCAL_FileNameBuf; UNLOCK(st->streamlock); - if (errno == ENOENT) + if (errno == ENOENT) { + free(args); return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s", fname, strerror(errno))); - else { + } else { return (PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, file_name, "%s: %s", fname, strerror(errno))); } @@ -1310,6 +1315,7 @@ do_open(Term file_name, Term t2, if (script) open_header(sno, open_mode); + free(args); UNLOCK(st->streamlock); { Term t = Yap_MkStream(sno); diff --git a/os/streams.c b/os/streams.c index a567e82b6..b77fe0584 100644 --- a/os/streams.c +++ b/os/streams.c @@ -670,6 +670,7 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */ // done det = (p == STREAM_PROPERTY_END); } + free( args ); if (rc) { if (det) cut_succeed(); @@ -720,9 +721,11 @@ static Int stream_property(USES_REGS1) { /* Init current_stream */ } if (do_stream_property(i, args PASS_REGS)) { UNLOCK(GLOBAL_Stream[i].streamlock); + free( args ); cut_succeed(); } else { UNLOCK(GLOBAL_Stream[i].streamlock); + free( args ); cut_fail(); } } else { @@ -912,17 +915,6 @@ static void CloseStream(int sno) { close(GLOBAL_Stream[sno].u.pipe.fd); } else if (GLOBAL_Stream[sno].status & (InMemory_Stream_f)) { Yap_CloseMemoryStream(sno); - if (GLOBAL_Stream[sno].file == NULL) { - char *s = GLOBAL_Stream[sno].u.mem_string.buf; - if (s == LOCAL_FileNameBuf || - s == LOCAL_FileNameBuf2) - return; - if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_CODE) - Yap_FreeAtomSpace(s); - else if (GLOBAL_Stream[sno].u.mem_string.src == MEM_BUF_MALLOC) { - free(s); - } - } } GLOBAL_Stream[sno].status = Free_Stream_f; Yap_DeleteAliases(sno); @@ -1026,7 +1018,7 @@ static Int set_output(USES_REGS1) { /* '$show_stream_position'(+Stream,Pos) */ static Int p_user_file_name(USES_REGS1) { Term tout; int sno = - Yap_CheckStream(ARG1, Input_Stream_f | Output_Stream_f | Append_Stream_f, + Yap_CheckStream(ARG1, Input_Stream_f | Output_Stream_f | Append_Stream_f, "user_file_name/2"); if (sno < 0) return (FALSE); diff --git a/os/writeterm.c b/os/writeterm.c index b47f6928b..fa23c49b5 100644 --- a/os/writeterm.c +++ b/os/writeterm.c @@ -290,11 +290,14 @@ static Int write_term2(USES_REGS1) { } yhandle_t mySlots = Yap_StartSlots(); int output_stream = LOCAL_c_output_stream; - if (output_stream == -1) + if (output_stream == -1) { + free( args ); output_stream = 1; + } LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -313,11 +316,14 @@ static Int write_term3(USES_REGS1) { return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); - if (output_stream < 0) + if (output_stream < 0) { + free( args ); return false; + } yhandle_t mySlots = Yap_StartSlots(); write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -346,6 +352,7 @@ static Int write2(USES_REGS1) { args[WRITE_NUMBERVARS].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -372,6 +379,7 @@ static Int write1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -400,6 +408,7 @@ static Int write_canonical1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -418,8 +427,10 @@ static Int write_canonical(USES_REGS1) { return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); - if (output_stream < 0) + if (output_stream < 0) { + free( args ); return false; + } yhandle_t mySlots = Yap_StartSlots(); args[WRITE_IGNORE_OPS].used = true; args[WRITE_IGNORE_OPS].tvalue = TermTrue; @@ -427,6 +438,7 @@ static Int write_canonical(USES_REGS1) { args[WRITE_QUOTED].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -446,15 +458,17 @@ static Int writeq1(USES_REGS1) { } yhandle_t mySlots = Yap_StartSlots(); int output_stream = LOCAL_c_output_stream; - if (output_stream == -1) + if (output_stream == -1) { + free( args ); output_stream = 1; + } args[WRITE_NUMBERVARS].used = true; args[WRITE_NUMBERVARS].tvalue = TermTrue; args[WRITE_QUOTED].used = true; args[WRITE_QUOTED].tvalue = TermTrue; write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -473,8 +487,10 @@ static Int writeq(USES_REGS1) { return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); - if (output_stream < 0) + if (output_stream < 0) { + free( args ); return false; + } yhandle_t mySlots = Yap_StartSlots(); args[WRITE_NUMBERVARS].used = true; args[WRITE_NUMBERVARS].tvalue = TermTrue; @@ -482,6 +498,7 @@ static Int writeq(USES_REGS1) { args[WRITE_QUOTED].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -501,8 +518,10 @@ static Int print1(USES_REGS1) { } yhandle_t mySlots = Yap_StartSlots(); int output_stream = LOCAL_c_output_stream; - if (output_stream == -1) + if (output_stream == -1) { + free( args ); output_stream = 1; + } args[WRITE_PORTRAY].used = true; args[WRITE_PORTRAY].tvalue = TermTrue; args[WRITE_NUMBERVARS].used = true; @@ -510,6 +529,7 @@ static Int print1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -528,8 +548,10 @@ static Int print(USES_REGS1) { return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); - if (output_stream < 0) + if (output_stream < 0) { + free( args ); return false; + } yhandle_t mySlots = Yap_StartSlots(); args[WRITE_PORTRAY].used = true; args[WRITE_PORTRAY].tvalue = TermTrue; @@ -537,6 +559,7 @@ static Int print(USES_REGS1) { args[WRITE_NUMBERVARS].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -563,6 +586,7 @@ static Int writeln1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -579,8 +603,10 @@ static Int writeln(USES_REGS1) { return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "writeln/2"); - if (output_stream < 0) - return false; + if (output_stream < 0) { + free( args ); +return false; + } yhandle_t mySlots = Yap_StartSlots(); args[WRITE_NL].used = true; args[WRITE_NL].tvalue = TermTrue; @@ -588,6 +614,7 @@ static Int writeln(USES_REGS1) { args[WRITE_NUMBERVARS].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); + free( args ); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE);