title: DBus : transmit a Data Array but crash
body: <p>I would like to transmit a data array from one application to the other via DBus.</p>
  
  <p>My code as below:</p>
  
  <p>server.c:  </p>
  
  <pre><code>/* server.c */
  
  #include &lt;dbus/dbus.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  DBusHandlerResult filter_func(DBusConnection *connection, 
    DBusMessage *message, void *usr_data)
  {
      DBusMessage *reply;
      dbus_bool_t handled = false;
      char *pReadData;
      unsigned char len;
      unsigned char i;
  
      DBusError dberr;
  
      dbus_error_init(&amp;dberr);
  
       printf("pReadData = %x\n", (unsigned int)pReadData);
  
     if(FALSE == dbus_message_get_args(message, &amp;dberr, DBUS_TYPE_ARRAY,
   DBUS_TYPE_BYTE, &amp;pReadData, &amp;len,  DBUS_TYPE_INVALID) &amp;&amp; 0 != len)
   {
     //printf("len = %d\n");
     //printf("receiver data error\n");
     return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
   }
  
    if(0 == len)
      return DBUS_HANDLER_RESULT_HANDLED;
  
    printf("len = %d, ", len);
  
    for( i = 0; i &lt; len; i++)
       printf("%#2x ", (unsigned char)pReadData[i]);
    printf("\n");    
    handled = true;
  
    printf("pReadData = %x\n", (unsigned int)pReadData);
  
    /*if one free pReadData, it will crash!*/
  //dbus_free_string_array((char**)&amp;pReadData);
  
     return (handled ? DBUS_HANDLER_RESULT_HANDLED :
    DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
  
  }/*filter_func*/
  
  
  int main(int argc, char *argv[])
  {
      DBusError dberr;
      DBusConnection *dbconn;
  
       dbus_error_init(&amp;dberr);
       dbconn = dbus_bus_get(DBUS_BUS_SESSION, &amp;dberr);
  
      if (!dbus_connection_add_filter(dbconn, filter_func, NULL, NULL)) {
         return -1;
      }
  
      dbus_bus_add_match(dbconn,      "type='signal',interface='gaiger.Drstein.Demonstration'", &amp;dberr);
  
       while(dbus_connection_read_write_dispatch(dbconn, -1)) {
           /* loop */
       }
  
        return 0;
  }/*main*/
  </code></pre>
  
  <p>And client.c</p>
  
  <pre><code>#include &lt;dbus/dbus.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int db_send(DBusConnection *dbconn)
  {
       DBusMessage *dbmsg;
       char *pSendData;
       unsigned char len;
       unsigned char i;
  
       pSendData = (char *)malloc(256);
  
       dbmsg = dbus_message_new_signal("/client/signal/Object", 
         "gaiger.Drstein.Demonstration", "Test");
  
       len = 6;
       for(i = 0; i &lt; len; i++)
       pSendData[i] = (unsigned char)i;
  
       if (!dbus_message_append_args(dbmsg, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE, 
      &amp;pSendData,  len, DBUS_TYPE_INVALID)) 
      {
         return -1;
      }
  
      if (!dbus_connection_send(dbconn, dbmsg, NULL)) {
           return -1;
      }
  
      dbus_connection_flush(dbconn);
      printf("send message : len = %d, ", len );
  
      for( i = 0; i &lt; len; i++)
        printf("%#x ", (unsigned char)pSendData[i]);
  
      printf("\n"); 
        dbus_message_unref(dbmsg);    
      free(pSendData);
  
      return 0;
   }/**/
  
  
   int main(int argc, char *argv[])
   {
      unsigned int i;
      DBusError dberr;
      DBusConnection *dbconn;
  
      dbus_error_init(&amp;dberr);
  
       dbconn = dbus_bus_get(DBUS_BUS_SESSION, &amp;dberr);
  
   #if(1)    
       for(i = 0; i &lt; 3; i++)
       db_send(dbconn);
   #else
       while(dbus_connection_read_write_dispatch(dbconn, -1)) {
         db_send(dbconn);
       }
   #endif  
  
       dbus_connection_unref(dbconn);
       return 0;
   }
  </code></pre>
  
  <p>The code works in Ubuntu 14.4, x86-64, but it crash in printing received data in Fedora 21, x86-32, virtual machine.</p>
  
  <p>For the line :</p>
  
  <pre><code>if(FALSE == dbus_message_get_args(message, &amp;dberr, DBUS_TYPE_ARRAY, 
  DBUS_TYPE_BYTE, &amp;pReadData, &amp;len,  DBUS_TYPE_INVALID) &amp;&amp; 0 != len)
  </code></pre>
  
  <p>I know the pointer pReadData would be allocated by dbus itself, the address value after this line is 0x90000 in Fedora 21, it is very odd number. </p>
  
  <p>How should I do to avoid crash but print received data values in Fedora 21 x86 32bit?</p>
  
  <p>Thank your help.</p>