Bug 241

Summary: bad output for filename in slonik echo output
Product: Slony-I Reporter: Steve Singer <ssinger>
Component: slonikAssignee: Slony Bugs List <slony1-bugs>
Status: NEW ---    
Severity: enhancement CC: slony1-bugs
Priority: low    
Version: 2.0   
Hardware: PC   
OS: Linux   

Description Steve Singer 2011-09-28 08:22:31 UTC
As reported on the mailing list.

Its version 2.0.7


    include <u2_preamble.sk>;
    include <gen_newslave.sk>;


    cluster name = sl;

    define node1_conninfo 'blah blah blah';
    define node2_conninfo 'more blah';

    node 1 admin conninfo = @node1_conninfo;
    node 2 admin conninfo = @node2_conninfo;


    include <gen_sync.sk>;

    echo 'Adding node 2';
    store node (id=2, comment=@node2_conninfo, event node=1);
    echo 'Creating paths';
    store path (server=1, client=2, conninfo=@node1_conninfo);
    store path (server=2, client=1, conninfo=@node2_conninfo);
    include <gen_sync.sk>;

    echo 'Subscribing node 2';
    subscribe set (id=1,provider=1,receiver=2,forward=yes);
    wait for event (origin=1, confirmed=all, wait on=1, timeout=0);
    echo 'Subscription created. Slave is copying data. Master can go live.';


    echo 'Waiting for sync';
    sync (id=1);
    wait for event (origin=1, confirmed=all, wait on=1, timeout=0);
    echo 'Synced';

Results in

$ slonik u2_newslave.sk
:1: Waiting for sync
:4: Synced
gen_newslave.sk:3: Adding node 2
gen_newslave.sk:5: Creating paths
Subscribing node 2:1: Waiting for sync
Subscribing node 2:4: Synced
/lib/libnsl.so.1:10: Subscribing node 2
/lib/libnsl.so.1:13: Subscription created. Slave is copying data. Master can go live.

Comment 1 Steve Singer 2011-09-28 08:26:05 UTC
I *THINK the problem here is that

in scan.l when processing an include directive we strdup() the filename and
pass this to pushBuffer().  This sets current_file to the memory allocated by strdup.  As the parser runs it stores a pointer to current_file into the structures that the parser creates.

When processing of that file ends popBuffer() calls free(current_file).  This will deallocate the memory even though the structures created by the parser still might point at that memory.

In parser.y should we be calling strdup(current_file) to create a new copy of the filename for storing in the parser structures?