build-sys: Check return values and NULL ctx
The referenced commit introduced a test program for the API but it would often fail due to: The given pointer for _new() not being NULL The return value for _new not checked, so the subsequent _unref() would free() random memory slabinfo checks failing due to permission denied errors. The first two are fixed, as well as returning a fail to the test if they don't return correctly, with slabinfo waiting to see if there is a way of initialising the structure without reading the slabinfo. References: commit e616409aa497b5dc656dc7a5bd0a21adf0ee4d36 Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
parent
e616409aa4
commit
4eeed6dcff
@ -29,58 +29,52 @@
|
|||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
|
||||||
static int check_diskstats (void *data) {
|
static int check_diskstats (void *data) {
|
||||||
struct diskstats_info *ctx;
|
struct diskstats_info *ctx = NULL;
|
||||||
testname = "Itemtable check, diskstats";
|
testname = "Itemtable check, diskstats";
|
||||||
procps_diskstats_new(&ctx);
|
if (procps_diskstats_new(&ctx) < 0) return 0;
|
||||||
procps_diskstats_unref(&ctx);
|
return (procps_diskstats_unref(&ctx) == 0);
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_meminfo (void *data) {
|
static int check_meminfo (void *data) {
|
||||||
struct meminfo_info *ctx;
|
struct meminfo_info *ctx = NULL;
|
||||||
testname = "Itemtable check, meminfo";
|
testname = "Itemtable check, meminfo";
|
||||||
procps_meminfo_new(&ctx);
|
if (procps_meminfo_new(&ctx) < 0) return 0;
|
||||||
procps_meminfo_unref(&ctx);
|
return (procps_meminfo_unref(&ctx) == 0);
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_pids (void *data) {
|
static int check_pids (void *data) {
|
||||||
struct pids_info *ctx;
|
struct pids_info *ctx = NULL;;
|
||||||
testname = "Itemtable check, pids";
|
testname = "Itemtable check, pids";
|
||||||
procps_pids_new(&ctx, NULL, 0);
|
if (procps_pids_new(&ctx, NULL, 0) < 0) return 0;
|
||||||
procps_pids_unref(&ctx);
|
return (procps_pids_unref(&ctx) == 0);
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_slabinfo (void *data) {
|
static int check_slabinfo (void *data) {
|
||||||
struct slabinfo_info *ctx;
|
struct slabinfo_info *ctx = NULL;
|
||||||
testname = "Itemtable check, slabinfo";
|
testname = "Itemtable check, slabinfo";
|
||||||
procps_slabinfo_new(&ctx);
|
if (procps_slabinfo_new(&ctx) < 0) return 0;
|
||||||
procps_slabinfo_unref(&ctx);
|
return (procps_slabinfo_unref(&ctx) == 0);
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_stat (void *data) {
|
static int check_stat (void *data) {
|
||||||
struct stat_info *ctx;
|
struct stat_info *ctx = NULL;
|
||||||
testname = "Itemtable check, stat";
|
testname = "Itemtable check, stat";
|
||||||
procps_stat_new(&ctx);
|
if (procps_stat_new(&ctx) < 0) return 0;
|
||||||
procps_stat_unref(&ctx);
|
return (procps_stat_unref(&ctx) == 0);
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int check_vmstat (void *data) {
|
static int check_vmstat (void *data) {
|
||||||
struct vmstat_info *ctx;
|
struct vmstat_info *ctx = NULL;
|
||||||
testname = "Itemtable check, vmstat";
|
testname = "Itemtable check, vmstat";
|
||||||
procps_vmstat_new(&ctx);
|
if (procps_vmstat_new(&ctx) < 0) return 0;
|
||||||
procps_vmstat_unref(&ctx);
|
return (procps_vmstat_unref(&ctx) == 0);
|
||||||
return (1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static TestFunction test_funcs[] = {
|
static TestFunction test_funcs[] = {
|
||||||
check_diskstats,
|
check_diskstats,
|
||||||
check_meminfo,
|
check_meminfo,
|
||||||
check_pids,
|
check_pids,
|
||||||
check_slabinfo,
|
// check_slabinfo, EPERM errors
|
||||||
check_stat,
|
check_stat,
|
||||||
check_vmstat,
|
check_vmstat,
|
||||||
NULL
|
NULL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user