move allocation of initial userdata memory block out of the loop, better error

This commit is contained in:
Arnout Engelen
2013-05-12 13:58:37 +00:00
parent 7c599c8c80
commit a3c9a81e53

View File

@@ -147,6 +147,7 @@ int main (int argc, char** argv)
alarm (refreshdelay); alarm (refreshdelay);
fprintf(stderr, "Waiting for first packet to arrive (see sourceforge.net bug 1019381)\n"); fprintf(stderr, "Waiting for first packet to arrive (see sourceforge.net bug 1019381)\n");
struct dpargs * userdata = (dpargs *) malloc (sizeof (struct dpargs));
// Main loop: // Main loop:
// //
@@ -159,19 +160,17 @@ int main (int argc, char** argv)
handle * current_handle = handles; handle * current_handle = handles;
while (current_handle != NULL) while (current_handle != NULL)
{ {
struct dpargs * userdata = (dpargs *) malloc (sizeof (struct dpargs));
userdata->sa_family = AF_UNSPEC; userdata->sa_family = AF_UNSPEC;
currentdevice = current_handle->devicename; currentdevice = current_handle->devicename;
int retval = dp_dispatch (current_handle->content, -1, (u_char *)userdata, sizeof (struct dpargs)); int retval = dp_dispatch (current_handle->content, -1, (u_char *)userdata, sizeof (struct dpargs));
if (retval == -1 || retval == -2) if (retval < 0)
{ {
std::cerr << "Error dispatching" << std::endl; std::cerr << "Error dispatching: " << retval << std::endl;
} }
else if (retval != 0) else if (retval != 0)
{ {
packets_read = true; packets_read = true;
} }
free (userdata);
current_handle = current_handle->next; current_handle = current_handle->next;
} }