View Issue Details

IDProjectCategoryView StatusLast Update
0006645GNUnetutil librarypublic2020-11-11 13:54
Reportermd Assigned Toschanzen  
PrioritylowSeverityminorReproducibilityhave not tried
Status closedResolutionno change required 
PlatformGNU/LinuxOSGuix SystemOS Versionv???
Product VersionGit master 
Summary0006645: Trivial memory leak (and unused code) in GNUNET_CONTAINER_meta_data_serialize
DescriptionThe function GNUNET_CONTAINER_meta_data_serialize sometimes allocates vmd = (struct GNUNET_CONTAINER_MetaData *) md, but the result is never used or freed. On a related note, vmd->sbuf is allocated but never freed. I believe vmd shouldn't be allocated at all, and all references to vmd should be replaced by md, but I don't know the caching logic well enough to tell for sure.

Discovered on gnunet-0.13.1, also present on git master.

Relevant source code src/util/container_meta_data.c at line 893:

    if ((NULL == md->sbuf) && (0 == i))
    {
      /* fill 'sbuf'; this "modifies" md, but since this is only
       * an internal cache we will cast away the 'const' instead
       * of making the API look strange. */
      vmd = (struct GNUNET_CONTAINER_MetaData *) md;
      hdr = GNUNET_malloc (left + sizeof(struct MetaDataHeader));
      hdr->size = htonl (left);
      hdr->entries = htonl (md->item_count);
      if (GNUNET_YES == comp)
      {
        GNUNET_assert (clen < left);
        hdr->version = htonl (2 | HEADER_COMPRESSED);
        GNUNET_memcpy (&hdr[1], cdata, clen);
        vmd->sbuf_size = clen + sizeof(struct MetaDataHeader);
      }
      else
      {
        hdr->version = htonl (2);
        GNUNET_memcpy (&hdr[1], &ent[0], left);
        vmd->sbuf_size = left + sizeof(struct MetaDataHeader);
      }
      vmd->sbuf = (char *) hdr;
    }
Tagslow hanging fruit

Activities

schanzen

2020-11-11 10:46

administrator   ~0017118

vmd is never allocated. It is simply assigned. As per the comment, the reason behind this is to remove the "const" from the MetaData object "md" in order to "modify" the "sbuf" member if NULL.
I do not think this is a memory leak.

md

2020-11-11 11:19

reporter   ~0017121

You're right, I didn't read that line properly ... The issue can be closed.

Issue History

Date Modified Username Field Change
2020-11-10 19:55 md New Issue
2020-11-10 19:55 md Tag Attached: low hanging fruit
2020-11-11 10:46 schanzen Note Added: 0017118
2020-11-11 11:19 md Note Added: 0017121
2020-11-11 13:54 schanzen Assigned To => schanzen
2020-11-11 13:54 schanzen Status new => closed
2020-11-11 13:54 schanzen Resolution open => no change required