我有以下结构:
typedef struct pair {
int *key; // search key for this item
int *count; // pointer to data for this item
struct pair *next; // children
} pair_t;
typedef struct counters {
struct pair *head;
} counters_t;
Run Code Online (Sandbox Code Playgroud)
我有以下功能:
static pair_t * // not visible outside this file
pair_new(const int key)
{
pair_t *pair = malloc(sizeof(pair_t));
free(pair->key);
free(pair->count);
if (pair == NULL) {
// error allocating memory for pair; return error
return NULL;
} else {
pair->key = malloc(sizeof(int));
pair->count …Run Code Online (Sandbox Code Playgroud)