]> git.proxmox.com Git - mirror_ovs.git/commit
ovsdb-idlc: Fix memory leak reported by Coverity.
authorWilliam Tu <u9012063@gmail.com>
Sat, 2 May 2020 16:01:48 +0000 (09:01 -0700)
committerWilliam Tu <u9012063@gmail.com>
Tue, 12 May 2020 15:34:52 +0000 (08:34 -0700)
commit6187bd3aa00dff30b7db3414381e750ecf8ab777
treec1b021b7e3a90cb0cecffb5c84253b1d8a91a99b
parent732cb79fb867b99b697da4cd305a3903a680454a
ovsdb-idlc: Fix memory leak reported by Coverity.

Coverity shows the following memory leak in this code pattern:

void
ovsrec_ipfix_index_set_obs_domain_id(...
{
    struct ovsdb_datum datum;
//     1. alloc_fn: Storage is returned from allocation function xmalloc.
//     2. var_assign: Assigning: key = storage returned from xmalloc(16UL).
    union ovsdb_atom *key = xmalloc(sizeof(union ovsdb_atom));

//     3. Condition n_obs_domain_id, taking false branch.
    if (n_obs_domain_id) {
        datum.n = 1;
        datum.keys = key;
        key->integer = *obs_domain_id;
    } else {
        datum.n = 0;
        datum.keys = NULL;
    }
    datum.values = NULL;
    ovsdb_idl_index_write(CONST_CAST(struct ovsdb_idl_row *, &row->head...
//     CID 1420891 (#1 of 1): Resource leak (RESOURCE_LEAK)

Fixed it by moving the xmalloc to the true branch.

Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
Signed-off-by: William Tu <u9012063@gmail.com>
ovsdb/ovsdb-idlc.in