<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>13380</bug_id>
          
          <creation_ts>2019-06-07 14:46:05 +0000</creation_ts>
          <short_desc>Freeing an uninitialized pointer. (pkg-&gt;tags)</short_desc>
          <delta_ts>2019-09-16 15:04:38 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>6</classification_id>
          <classification>Yocto Project Subprojects</classification>
          <product>opkg</product>
          <component>opkg</component>
          <version>1.0</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Undecided</priority>
          <bug_severity>minor</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>lnksz.dev</reporter>
          <assigned_to name="Alejandro del Castillo">alejandro.delcastillo</assigned_to>
          
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>84100</commentid>
    <comment_count>0</comment_count>
    <who name="">lnksz.dev</who>
    <bug_when>2019-06-07 14:46:05 +0000</bug_when>
    <thetext>Freeing an uninitialized pointer.

```c
pkg_t pkg;
pkg_init_from_file(&amp;next, &quot;/tmp/some.ipk&quot;); // This calls pkg_init() under the hood
// Use pkg here
pkg_deinit(&amp;pkg); // ==&gt; free(pkg-&gt;tags) freeing an uninitialized pointer
```


This is not surfacing if one uses the pkg_new() call, as the underlaying calloc() sets this to 0, which could be NULL, so the free is ok. But as the described method is also legit by the API and spares a possible memory leak, the init should be added.

patch:
```
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -85,6 +85,7 @@ pkg_init(pkg_t *pkg)
      pkg-&gt;maintainer = NULL;
      pkg-&gt;section = NULL;
      pkg-&gt;description = NULL;
+     pkg-&gt;tags = NULL;
      pkg-&gt;state_want = SW_UNKNOWN;
      pkg-&gt;wanted_by = pkg_vec_alloc();
      pkg-&gt;state_flag = SF_OK;

```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>84978</commentid>
    <comment_count>1</comment_count>
    <who name="Alejandro del Castillo">alejandro.delcastillo</who>
    <bug_when>2019-09-16 15:04:38 +0000</bug_when>
    <thetext>Applied patch on 7e032d8720b34722b3d9be732cb8620912e4dc96</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>