Bug 13380

Summary: Freeing an uninitialized pointer. (pkg->tags)
Product: [Yocto Project Subprojects] opkg Reporter: lnksz.dev
Component: opkgAssignee: Alejandro del Castillo <alejandro.delcastillo>
Status: RESOLVED FIXED QA Contact:
Severity: minor    
Priority: Undecided    
Version: 1.0   
Target Milestone: ---   
Hardware: All   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description lnksz.dev 2019-06-07 14:46:05 UTC
Freeing an uninitialized pointer.

```c
pkg_t pkg;
pkg_init_from_file(&next, "/tmp/some.ipk"); // This calls pkg_init() under the hood
// Use pkg here
pkg_deinit(&pkg); // ==> free(pkg->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->maintainer = NULL;
      pkg->section = NULL;
      pkg->description = NULL;
+     pkg->tags = NULL;
      pkg->state_want = SW_UNKNOWN;
      pkg->wanted_by = pkg_vec_alloc();
      pkg->state_flag = SF_OK;

```
Comment 1 Alejandro del Castillo 2019-09-16 15:04:38 UTC
Applied patch on 7e032d8720b34722b3d9be732cb8620912e4dc96