This makes it easier to see memory leaks in the code under test.
Found with valgrind.
/*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
ok = print_and_free_json(json_from_stream(stream));
}
+ fclose(stream);
+
return !ok;
}
}
poll_block();
}
+ free(rpcs);
+ pstream_close(pstream);
}
-
static void
do_request(int argc UNUSED, char *argv[])
{
/*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
static void
run_lock_blocks_other_process(void)
{
- struct lockfile *lockfile;
+ /* Making this static prevents a memory leak warning from valgrind for the
+ * parent process, which cannot easily unlock (and free) 'lockfile' because
+ * it can only do so after the child has exited, and it's the caller of
+ * this function that does the wait() call. */
+ static struct lockfile *lockfile;
assert(lockfile_lock("file", 0, &lockfile) == 0);
if (do_fork() == CHILD) {
+ lockfile_unlock(lockfile);
assert(lockfile_lock("file", 0, &lockfile) == EAGAIN);
exit(11);
}
assert(lockfile_lock("file", 0, &lockfile) == 0);
if (do_fork() == CHILD) {
+ lockfile_unlock(lockfile);
assert(lockfile_lock("file", TIME_UPDATE_INTERVAL * 3,
&lockfile) == 0);
exit(11);
assert(lockfile_lock("file", 0, &lockfile) == 0);
if (do_fork() == CHILD) {
+ lockfile_unlock(lockfile);
assert(lockfile_lock("file", TIME_UPDATE_INTERVAL,
&lockfile) == ETIMEDOUT);
exit(11);
/*
- * Copyright (c) 2009 Nicira Networks.
+ * Copyright (c) 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
check_ovsdb_error(struct ovsdb_error *error)
{
if (error) {
- ovs_fatal(0, "%s", ovsdb_error_to_string(error));
+ char *s = ovsdb_error_to_string(error);
+ ovsdb_error_destroy(error);
+ ovs_fatal(0, "%s", s);
}
}
char *s = ovsdb_error_to_string(error);
printf("%s: %s failed: %s\n", name, command, s);
free(s);
+ ovsdb_error_destroy(error);
} else {
printf("%s: %s successful\n", name, command);
}
ovsdb_atom_destroy(&atoms[i], type);
}
print_and_free_json(json_array_create(json_atoms, n_atoms));
+ free(atoms);
}
static void
}
}
}
+ for (i = 0; i < n_rows; i++) {
+ ovsdb_row_destroy(rows[i]);
+ free(names[i]);
+ }
free(rows);
free(names);
for (i = 0; i < n_conditions; i++) {
ovsdb_condition_destroy(&conditions[i]);
}
+ free(conditions);
for (i = 0; i < n_rows; i++) {
ovsdb_row_destroy(rows[i]);
}
+ free(rows);
ovsdb_table_destroy(table); /* Also destroys 'ts'. */
}
for (i = 0; i < n_sets; i++) {
ovsdb_mutation_set_destroy(&sets[i]);
}
+ free(sets);
for (i = 0; i < n_rows; i++) {
ovsdb_row_destroy(rows[i]);
}
+ free(rows);
ovsdb_table_destroy(table); /* Also destroys 'ts'. */
}
result = ovsdb_execute(db, params, 0, NULL);
s = json_to_string(result, JSSF_SORT);
printf("%s\n", s);
+ free(s);
json_destroy(params);
json_destroy(result);
}
result = ovsdb_trigger_steal_result(&t->trigger);
s = json_to_string(result, JSSF_SORT);
printf("t=%lld: trigger %d (%s): %s\n", now, t->number, title, s);
+ free(s);
json_destroy(result);
ovsdb_trigger_destroy(&t->trigger);
free(t);
/*
- * Copyright (c) 2008, 2009 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
struct bpdu *bpdu = &b->rxq[b->rxq_tail % RXQ_SIZE];
stp_received_bpdu(stp_get_port(b->stp, bpdu->port_no),
bpdu->data, bpdu->size);
+ free(bpdu->data);
any = true;
}
}
pos++;
}
if (*pos == '\0') {
+ free(token);
token = NULL;
return false;
}
err("trailing garbage on line");
}
}
+ free(token);
+
+ for (i = 0; i < tc->n_lans; i++) {
+ struct lan *lan = tc->lans[i];
+ free((char *) lan->name);
+ free(lan);
+ }
+ for (i = 0; i < tc->n_bridges; i++) {
+ struct bridge *bridge = tc->bridges[i];
+ stp_destroy(bridge->stp);
+ free(bridge);
+ }
+ free(tc);
return 0;
}
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
} else if (!strcmp(argv[1], "daemon")) {
/* Test that time still advances even in a daemon. This is an
* interesting test because fork() cancels the interval timer. */
- char cwd[1024];
+ char cwd[1024], *pidfile;
FILE *success;
assert(getcwd(cwd, sizeof cwd) == cwd);
/* Daemonize, with a pidfile in the current directory. */
set_detach();
- set_pidfile(xasprintf("%s/test-timeval.pid", cwd));
+ pidfile = xasprintf("%s/test-timeval.pid", cwd);
+ set_pidfile(pidfile);
+ free(pidfile);
set_no_chdir();
daemonize();