hw/xen: Use g_free instead of free and fix potential memory leaks
The wrong functions and the missing calls of g_free were reported by cppcheck. Signed-off-by: Stefan Weil <sw@weilnetz.de> Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
This commit is contained in:
		
							parent
							
								
									1e2a1d41f2
								
							
						
					
					
						commit
						c5633d998a
					
				@ -1777,12 +1777,12 @@ static int xen_pt_config_reg_init(XenPCIPassthroughState *s,
 | 
				
			|||||||
        rc = reg->init(s, reg_entry->reg,
 | 
					        rc = reg->init(s, reg_entry->reg,
 | 
				
			||||||
                       reg_grp->base_offset + reg->offset, &data);
 | 
					                       reg_grp->base_offset + reg->offset, &data);
 | 
				
			||||||
        if (rc < 0) {
 | 
					        if (rc < 0) {
 | 
				
			||||||
            free(reg_entry);
 | 
					            g_free(reg_entry);
 | 
				
			||||||
            return rc;
 | 
					            return rc;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (data == XEN_PT_INVALID_REG) {
 | 
					        if (data == XEN_PT_INVALID_REG) {
 | 
				
			||||||
            /* free unused BAR register entry */
 | 
					            /* free unused BAR register entry */
 | 
				
			||||||
            free(reg_entry);
 | 
					            g_free(reg_entry);
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        /* set register value */
 | 
					        /* set register value */
 | 
				
			||||||
 | 
				
			|||||||
@ -389,7 +389,7 @@ static int xen_remove_from_physmap(XenIOState *state,
 | 
				
			|||||||
    if (state->log_for_dirtybit == physmap) {
 | 
					    if (state->log_for_dirtybit == physmap) {
 | 
				
			||||||
        state->log_for_dirtybit = NULL;
 | 
					        state->log_for_dirtybit = NULL;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    free(physmap);
 | 
					    g_free(physmap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1030,7 +1030,7 @@ static void xen_read_physmap(XenIOState *state)
 | 
				
			|||||||
                xen_domid, entries[i]);
 | 
					                xen_domid, entries[i]);
 | 
				
			||||||
        value = xs_read(state->xenstore, 0, path, &len);
 | 
					        value = xs_read(state->xenstore, 0, path, &len);
 | 
				
			||||||
        if (value == NULL) {
 | 
					        if (value == NULL) {
 | 
				
			||||||
            free(physmap);
 | 
					            g_free(physmap);
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        physmap->start_addr = strtoull(value, NULL, 16);
 | 
					        physmap->start_addr = strtoull(value, NULL, 16);
 | 
				
			||||||
@ -1041,7 +1041,7 @@ static void xen_read_physmap(XenIOState *state)
 | 
				
			|||||||
                xen_domid, entries[i]);
 | 
					                xen_domid, entries[i]);
 | 
				
			||||||
        value = xs_read(state->xenstore, 0, path, &len);
 | 
					        value = xs_read(state->xenstore, 0, path, &len);
 | 
				
			||||||
        if (value == NULL) {
 | 
					        if (value == NULL) {
 | 
				
			||||||
            free(physmap);
 | 
					            g_free(physmap);
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        physmap->size = strtoull(value, NULL, 16);
 | 
					        physmap->size = strtoull(value, NULL, 16);
 | 
				
			||||||
@ -1069,12 +1069,14 @@ int xen_hvm_init(void)
 | 
				
			|||||||
    state->xce_handle = xen_xc_evtchn_open(NULL, 0);
 | 
					    state->xce_handle = xen_xc_evtchn_open(NULL, 0);
 | 
				
			||||||
    if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) {
 | 
					    if (state->xce_handle == XC_HANDLER_INITIAL_VALUE) {
 | 
				
			||||||
        perror("xen: event channel open");
 | 
					        perror("xen: event channel open");
 | 
				
			||||||
 | 
					        g_free(state);
 | 
				
			||||||
        return -errno;
 | 
					        return -errno;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    state->xenstore = xs_daemon_open();
 | 
					    state->xenstore = xs_daemon_open();
 | 
				
			||||||
    if (state->xenstore == NULL) {
 | 
					    if (state->xenstore == NULL) {
 | 
				
			||||||
        perror("xen: xenstore open");
 | 
					        perror("xen: xenstore open");
 | 
				
			||||||
 | 
					        g_free(state);
 | 
				
			||||||
        return -errno;
 | 
					        return -errno;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user