diff --git a/docs/labs/free.html b/docs/labs/free.html index d76f425b..6e699631 100644 --- a/docs/labs/free.html +++ b/docs/labs/free.html @@ -7,63 +7,11 @@ + - - - - - - - diff --git a/docs/labs/free.js b/docs/labs/free.js new file mode 100644 index 00000000..4cf2e3de --- /dev/null +++ b/docs/labs/free.js @@ -0,0 +1,57 @@ +info = +{ + hints: [ + { + present: String.raw`\s*free[^;]*; asprintf`, + text: "Do not free the input first, you need to use it.", + examples: [ + [ + "free(s);\nasprintf(&result, \"pre_%s_post\", s);" + ] + ] + }, + { + present: String.raw`\s* asprintf \(`, + absent: "free", + text: "This fails to free the memory, likely leading to a missing release.", + examples: [ + [ + "asprintf(&result, \"\"pre_%s_post\"\", s);" + ] + ] + }, + { + absent: "return", + text: "This fails to return the result." + }, + { + absent: String.raw`\s* [^;]+;[^;]+;[^;]+; \s*`, + text: "There should be 3 statements, each terminated with a semicolon.", + examples: [ + [ + "asprintf(&result, \"pre_%s_post\", s);\nfree(s);\nreturn result" + ] + ] + }, + { + present: String.raw`\s* return result ; free \s*`, + text: "Do not do anything after the return, it will not execute.", + examples: [ + [ + "asprintf(&result, \"pre_%s_post\", s);\nreturn result;\nfree(s);" + ] + ] + } + ], + expected: [ +` asprintf(&result, "pre_%s_post", s); + free(s); + return result;` + ], + correct: [ + String.raw`\s* + asprintf \( & result , "pre_%s_post" , s \) ; + free \( s \) ; + return result ; \s*` + ], +}