Thrift
  1. Thrift
  2. THRIFT-1389

c_glib_generator.cc generates leaking code for cassandra_client_get_slice() and cassandra_client_get()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.6.1
    • Fix Version/s: 0.9.2
    • Labels:
      None
    • Environment:

      Used with Cassandra 0.8.4 on Linux 2.6.32 with x86_64

      Description

      The generated cassandra.c cassandra_client_recv_get_slice() code for list processing instantiates an object of TYPE_COLUMN_OR_SUPER_COLUMN then calls thrift_struct_read() as in the following code snippet:

            switch (fid)
            {
              case 0:
                if (ftype == T_LIST)
                {
                  {
                    guint32 size;
                    ThriftType element_type;
                    if ((ret = thrift_protocol_read_list_begin (protocol, &element_type, &size, error)) < 0)
                      return 0;
                    xfer += ret;
      
                    /* iterate through list elements */
                    guint32 i;
                    for (i = 0; i < size; i++)
                    {
                      ColumnOrSuperColumn * _elem19;
                      _elem19 = g_object_new (TYPE_COLUMN_OR_SUPER_COLUMN, NULL);
                      //printf("\nrecv_slice made %p\n", _elem19->column);
                      if ((ret = thrift_struct_read (THRIFT_STRUCT (_elem19), protocol, error)) < 0)
      

      When the object of TYPE_COLUMN_OR_SUPER_COLUMN is instantiated, it in turn instantiates a child of TYPE_COLUMN:

      void
      column_or_super_column_instance_init (ColumnOrSuperColumn * object)
      {
        /* satisfy -Wall */
        THRIFT_UNUSED_VAR (object);
        object->column = g_object_new (TYPE_COLUMN, NULL);
        object->__isset_column = FALSE;
      

      But this instance reference is lost and replaced by a new TYPE_COLUMN instantiation reference when the column member is read by column_or_super_column_read() within the same execution context of the top level cassandra_client_recv_get_slice() call:

          switch (fid)
          {
            case 1:
              if (ftype == T_STRUCT)
              {
      
                this_object->column = g_object_new (TYPE_COLUMN, NULL);
                if ((ret = thrift_struct_read (THRIFT_STRUCT (this_object->column), protocol, error)) < 0)
      

      The above snippets/logic/leak described above for cassandra_client_get_slice() also apply for cassandra_client_get().

        Activity

        Jerry Gally created issue -
        Simon South made changes -
        Field Original Value New Value
        Description The generated cassandra.c cassandra_client_recv_get_slice() code for list processing instantiates an object of TYPE_COLUMN_OR_SUPER_COLUMN then calls thrift_struct_read() as in the following code snippet,:

        <... snip>
              switch (fid)
              {
                case 0:
                  if (ftype == T_LIST)
                  {
                    {
                      guint32 size;
                      ThriftType element_type;
                      if ((ret = thrift_protocol_read_list_begin (protocol, &element_type, &size, error)) < 0)
                        return 0;
                      xfer += ret;

                      /* iterate through list elements */
                      guint32 i;
                      for (i = 0; i < size; i++)
                      {
                        ColumnOrSuperColumn * _elem19;
                        _elem19 = g_object_new (TYPE_COLUMN_OR_SUPER_COLUMN, NULL);
                        //printf("\nrecv_slice made %p\n", _elem19->column);
                        if ((ret = thrift_struct_read (THRIFT_STRUCT (_elem19), protocol, error)) < 0)

        <\snip ...>

        When the object of TYPE_COLUMN_OR_SUPER_COLUMN is instantiated, it in-turn instantiates a child of TYPE_COLUMN:

        <... snip>
        void
        column_or_super_column_instance_init (ColumnOrSuperColumn * object)
        {
          /* satisfy -Wall */
          THRIFT_UNUSED_VAR (object);
          object->column = g_object_new (TYPE_COLUMN, NULL);
          object->__isset_column = FALSE;

        </snip ...>

        But this instance reference is lost and replaced by a new TYPE_COLUMN instantiation reference when the column member is read by column_or_super_column_read() within the same execution context of the top level cassandra_client_recv_get_slice() call:

        <... snip>

            switch (fid)
            {
              case 1:
                if (ftype == T_STRUCT)
                {

                  this_object->column = g_object_new (TYPE_COLUMN, NULL);
                  if ((ret = thrift_struct_read (THRIFT_STRUCT (this_object->column), protocol, error)) < 0)

        </snip ...>

        The above snippits/logic/leak described above for cassandra_client_get_slice() also apply for cassandra_client_get().
        The generated cassandra.c {{cassandra_client_recv_get_slice()}} code for list processing instantiates an object of {{TYPE_COLUMN_OR_SUPER_COLUMN}} then calls {{thrift_struct_read()}} as in the following code snippet:

        {noformat}
              switch (fid)
              {
                case 0:
                  if (ftype == T_LIST)
                  {
                    {
                      guint32 size;
                      ThriftType element_type;
                      if ((ret = thrift_protocol_read_list_begin (protocol, &element_type, &size, error)) < 0)
                        return 0;
                      xfer += ret;

                      /* iterate through list elements */
                      guint32 i;
                      for (i = 0; i < size; i++)
                      {
                        ColumnOrSuperColumn * _elem19;
                        _elem19 = g_object_new (TYPE_COLUMN_OR_SUPER_COLUMN, NULL);
                        //printf("\nrecv_slice made %p\n", _elem19->column);
                        if ((ret = thrift_struct_read (THRIFT_STRUCT (_elem19), protocol, error)) < 0)
        {noformat}

        When the object of {{TYPE_COLUMN_OR_SUPER_COLUMN}} is instantiated, it in turn instantiates a child of {{TYPE_COLUMN}}:

        {noformat}
        void
        column_or_super_column_instance_init (ColumnOrSuperColumn * object)
        {
          /* satisfy -Wall */
          THRIFT_UNUSED_VAR (object);
          object->column = g_object_new (TYPE_COLUMN, NULL);
          object->__isset_column = FALSE;
        {noformat}

        But this instance reference is lost and replaced by a new {{TYPE_COLUMN}} instantiation reference when the column member is read by {{column_or_super_column_read()}} within the same execution context of the top level {{cassandra_client_recv_get_slice()}} call:

        {noformat}
            switch (fid)
            {
              case 1:
                if (ftype == T_STRUCT)
                {

                  this_object->column = g_object_new (TYPE_COLUMN, NULL);
                  if ((ret = thrift_struct_read (THRIFT_STRUCT (this_object->column), protocol, error)) < 0)
        {noformat}

        The above snippets/logic/leak described above for {{cassandra_client_get_slice()}} also apply for {{cassandra_client_get()}}.
        Simon South made changes -
        Assignee Simon South [ simonsouth ]
        Simon South made changes -
        Fix Version/s 0.9 [ 12316294 ]
        Jake Farrell made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 0.9.2 [ 12324954 ]
        Fix Version/s 0.9 [ 12316294 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Simon South
            Reporter:
            Jerry Gally
          • Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development