afsocket: Memory leak fix

If the configuration stays the same during a reload, log_reader_set_peer_addr()
is already called.

Signed-off-by: Tibor Benke <ihrwein@gmail.com>
Hi,

We discussed this IRL, but to keep in the open: you shouldn't rely on the
exact refcount values, if you have a local reference (which you do as
self->peer_addr is a ref), then you can simply unref/ref again, even if the
objects are the same.

The reason is simple:

   - the LogReader has a ref (stored in reader->peer_addr)
   - you as AFSocketSourceConnection have a ref (self->peer_addr)

If you call unref in log_reader_set_peer_addr(), you drop the reader's
reference, then you can take and increase the refcount by using the
borrowed reference that you got as a parameter.

Parameters are always "borrowed" references (e.g. you can only keep them
for a long term if you actually ref them), return values on the other hand
tend to be real references, so the caller must take care of freeing them.

Cheers,


On Tue, Jul 15, 2014 at 8:44 AM, ihrwein <notifications@github.com> wrote:

> In modules/afsocket/afsocket-source.c:
>
> > @@ -99,7 +100,6 @@ afsocket_sc_init(LogPipe *s)
> >                           self->owner->transport_mapper->stats_source,
> >                           self->owner->super.super.id,
> >                           afsocket_sc_stats_instance(self));
> > -  log_reader_set_peer_addr(self->reader, self->peer_addr);
> >    log_pipe_append((LogPipe *) self->reader, s);
>
> I think it wouldn't so nice to drop a reference, then reuse it again. When
> the reference counter reaches 0, the object is freed, then we increment the
> reference with 1.
>
> Maybe the right thing would be checking the equality of peer_addr and
> self->peer_addr. When they are equal we do nothing, otherwise drop the old
> reference and use the new peer_addr.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/balabit/syslog-ng/pull/166/files#r14919327>.
>