Something I did not noticed yesterday. There is, very likely, a memory leak here in re_extract:

grammar/rainerscript.c:

    if(bMustFree) free(str);
    if(r[0].datatype == 'S') es_deleteStr(r[0].d.estr);
    if(r[2].datatype == 'S') es_deleteStr(r[2].d.estr);
    if(r[3].datatype == 'S') es_deleteStr(r[3].d.estr);
finalize_it:
    if(bHadNoMatch) {

Shouldn't the memory be free when finalizing after an unsuccessful match?

But then, it turns out applicable to most functions:

What if there is an argument which is a JSON object? It looks like it will leak every time. There should be some varFree() function for this.

And, at last, what if r[0].datatype is unitialized and equals 'S' by accident? Shouldn't there be initialization for every struct var?


--
Pavel Levshin


25.10.2013 1:18, Pavel Levshin:
Hello.

I hope it will be useful. Now, when local variables are real JSON containers, why don't extract all submatches at once? I've given it a try and it works. The patch is based on a current master-var-refactor, I am sorry for this mess. I will redo it if needed when the refactoring will be done.

I've extended re_extract to achieve this behaviour. Creation of a new function (re_extract_all) just for this would lead to code duplication. The modified function returns a container with all submatches on request. Submatches in the container are identified by index, where "0" is whole match. New behaviour is achieved by setting 'submatch' parameter to any negative number. For non-negative numbers, it works as it used to. Example:

# re_extract(expr, re, match, submatch, no-found)

    set $.str = "Testing 31 32 33 and so on";
set $.var = re_extract($.str, "^([[:alnum:]]+) ([0-9]+) ([0-9]+)", 0, -1, "nothing");
    set $!matches = $.var;            # container here
    set $!match2 = $.var!2;          # 2nd submatch

And here is the output of all these variables (with some magic template):

_local_ { "str": "Testing 31 32 33 and so on", "var": { "0": "Testing 31 32", "1": "Testing", "2": "31", "3": "32" } } _msg_ { "matches": { "0": "Testing 31 32", "1": "Testing", "2": "31", "3": "32" }, "match2": "31" }


By the way, this patch also fixes a bug with buffer overflow in re_extract.


--
Pavel Levshin



_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of 
sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE 
THAT.

Reply via email to