fixing leak
[oweals/gnunet.git] / src / monkey / gdbmi_connect.c
index a39fdf27f4e4beb3677055cf9c40aae72107d671..7ccae081af7146ad55414b21f47c4e9a63765239 100644 (file)
@@ -6,7 +6,8 @@
   Module: Connect.
   Comments:
   This module handles the dialog with gdb, including starting and stopping
-gdb.@p
+gdb.
+  @<p>
 
 GDB Bug workaround for "file -readnow": I tried to workaround a bug using
 it but looks like this option also have bugs!!!! so I have to use the
@@ -17,7 +18,7 @@ in a row.
 
 ***************************************************************************/
 
-#define _GNU_SOURCE
+#include "platform.h"
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -31,7 +32,11 @@ in a row.
 #include <signal.h>
 #include <sys/stat.h>
 #include <sys/time.h>
+
 #include "gdbmi.h"
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
 
 #ifndef TEMP_FAILURE_RETRY
  #define TEMP_FAILURE_RETRY(a) (a)
@@ -268,53 +273,42 @@ mi_output *mi_get_response_blk(mi_h *h)
    }
  do
    {
-    if (1)
-      {
-       /*
-        That's a must. If we just keep trying to read and failing things
-        become really sloooowwww. Instead we try and if it fails we wait
-        until something is available.
-        TODO: Implement something with the time out, a callback to ask the
-        application is we have to wait or not could be a good thing.
-       */
-       fd_set set;
-       struct timeval timeout;
-       int ret;
-
-       r=mi_get_response(h);
-       if (r)
-          return mi_retire_response(h);
-
-       FD_ZERO(&set);
-       FD_SET(h->from_gdb[0],&set);
-       timeout.tv_sec=h->time_out;
-       timeout.tv_usec=0;
-       ret=TEMP_FAILURE_RETRY(select(FD_SETSIZE,&set,NULL,NULL,&timeout));
-       if (!ret)
-         {
-          if (!mi_check_running(h))
-            {
-             h->died=1;
-             mi_error=MI_GDB_DIED;
-             return NULL;
-            }
-          if (h->time_out_cb)
-             ret=h->time_out_cb(h->time_out_cb_data);
-          if (!ret)
-            {
-             mi_error=MI_GDB_TIME_OUT;
-             return NULL;
-            }
-         }
-      }
-    else
-      {
-       r=mi_get_response(h);
-       if (r)
-          return mi_retire_response(h);
-       else
-          usleep(100);
-      }
+   /*
+    That's a must. If we just keep trying to read and failing things
+    become really sloooowwww. Instead we try and if it fails we wait
+    until something is available.
+    TODO: Implement something with the time out, a callback to ask the
+    application is we have to wait or not could be a good thing.
+   */
+   fd_set set;
+   struct timeval timeout;
+   int ret;
+
+   r=mi_get_response(h);
+   if (r)
+      return mi_retire_response(h);
+
+   FD_ZERO(&set);
+   FD_SET(h->from_gdb[0],&set);
+   timeout.tv_sec=h->time_out;
+   timeout.tv_usec=0;
+   ret=TEMP_FAILURE_RETRY(select(FD_SETSIZE,&set,NULL,NULL,&timeout));
+   if (!ret)
+     {
+      if (!mi_check_running(h))
+        {
+         h->died=1;
+         mi_error=MI_GDB_DIED;
+         return NULL;
+        }
+      if (h->time_out_cb)
+         ret=h->time_out_cb(h->time_out_cb_data);
+      if (!ret)
+        {
+         mi_error=MI_GDB_TIME_OUT;
+         return NULL;
+        }
+     }
    }
  while (!r);
 
@@ -336,9 +330,9 @@ void mi_send_commands(mi_h *h, const char *file)
    {
     if (fgets(b,PATH_MAX,f))
       {
-       //printf("Send: %s\n",b);
-       mi_send(h,b);
-       mi_res_simple_done(h);
+       //printf("Send: %s\n",b);
+       mi_send (h, "%s", b);
+       mi_res_simple_done(h);
       }
    }
  fclose(f);
@@ -437,7 +431,7 @@ mi_h *mi_connect_local()
 /**[txh]********************************************************************
 
   Description:
-  Close connection. You should ask gdb to quit first @x{gmi_gdb_exit}.
+  Close connection. You should ask gdb to quit first gmi_gdb_exit.
   
 ***************************************************************************/
 
@@ -561,11 +555,18 @@ int mi_send(mi_h *h, const char *format, ...)
  va_start(argptr,format);
  ret=vasprintf(&str,format,argptr);
  va_end(argptr);
- fputs(str,h->to);
- fflush(h->to);
- if (h->to_gdb_echo)
-    h->to_gdb_echo(str,h->to_gdb_echo_data);
- free(str);
+ if (-1 != ret)
+   {
+     fputs(str,h->to);
+     fflush(h->to);
+     if (h->to_gdb_echo)
+       h->to_gdb_echo(str,h->to_gdb_echo_data);
+     free(str);
+   }
+ else
+   {
+     abort ();
+   }
 
  return ret;
 }
@@ -626,7 +627,7 @@ char *mi_search_in_path(const char *file)
  if (!path)
     return NULL;
  pt=strdup(path);
- r=strtok(pt,":");
+ r=strtok(pt,PATH_SEPARATOR_STR);
  while (r)
    {
     strcpy(test,r);
@@ -637,7 +638,7 @@ char *mi_search_in_path(const char *file)
        free(pt);
        return strdup(test);
       }
-    r=strtok(NULL,":");
+    r=strtok(NULL,PATH_SEPARATOR_STR);
    }
  free(pt);
  return NULL;
@@ -701,7 +702,7 @@ const char *mi_get_main_func()
   Description:
   Opens a new xterm to be used by the child process to debug.
   
-  Return: A new mi_aux_term structure, you can use @x{gmi_end_aux_term} to
+  Return: A new mi_aux_term structure, you can use gmi_end_aux_term to
 release it.
   
 ***************************************************************************/
@@ -849,7 +850,7 @@ void mi_force_version(mi_h *h, unsigned vMajor, unsigned vMiddle,
 /**[txh]********************************************************************
 
   Description:
-  Dis/Enables the @var{wa} workaround for a bug in gdb.
+  Dis/Enables the workaround for a bug in gdb.
 
 ***************************************************************************/
 
@@ -866,7 +867,7 @@ void mi_set_workaround(unsigned wa, int enable)
 /**[txh]********************************************************************
 
   Description:
-  Finds if the @var{wa} workaround for a bug in gdb is enabled.
+  Finds if the workaround for a bug in gdb is enabled.
   
   Return: !=0 if enabled.