[Nagiosplug-devel] Segfault in check_ping (need help fixing)
Matthias Eble
matthias.eble at mailing.kaufland-informationssysteme.com
Wed May 2 08:54:59 CEST 2007
Hi Thomas,
I'm no C wizard also, but I'll try to send you my opinions since you've
got no reply up to now.
>
> My two guesses are:
>
> 1) cmd == NULL. In some plugins I saw things such as
> output = strdup ("");
> [...]
> asprintf (&output, ...
>
> Is this the RightThing(tm) to do? Could it be the cause?
i think it depends on the situation. it should be fine here since
From asprintf manpage:
The functions asprintf() and vasprintf() are analogues of sprintf() and
vsprintf(), except that they allocate a string large enough to hold the
output including the terminating null byte, and return a pointer to it
via the first parameter. This pointer should be passed to free(3) to
release the allocated storage when it is no longer needed.
if asprintf reallocs the space, both should be fine. if there is a
malloc, i'd say, the empty string (but \0 terminated) would remain
allocated but unused..
>
> 2) mallos/realloc's
> char **addresses = NULL;
> [...]
> addresses = malloc (sizeof(char*) * max_addr);
> [...]
> addresses = realloc (addresses, sizeof(char*) * max_addr);
>
> I understand the concept of malloc/realloc but when it comes to fancy
> sizes I always get lost in pointers. Anyone skilled enough could verify
> that these alloc enough memory?
the realloc won't be called until multiple -H options are given.. so I
thinks this is not the problem
passing multiple -H args seems to be an undocumented feature though.
If I understood the source right, the second,... hosts will only be
pinged if the previous check was state unknown.
> Since I cannot reproduce the segfault I can't test it, and the user
> reporting this left.
hmm..
that's bad. I have only a centos 5 box here at the moment..
hth
matthias
More information about the Devel
mailing list