Skip to content

Commit

Permalink
solve memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
core software devel committed Aug 7, 2024
1 parent 8cd76ce commit 8a28395
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
7 changes: 3 additions & 4 deletions src/license.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,18 @@ void normalize_license(char *license)
{
char def[MAX_ARGLN];
strcpy(def, license_normalization[i]);
char *token;

/* get the first token */
token = strtok(def, ",");
char * token = strtok(def, ",");

char *spdx = token;
//char *spdx = token;

/* walk through other tokens */
while (token != NULL)
{
if (stricmp(license, token))
{
strcpy(license, spdx);
strcpy(license, token);
return;
}
token = strtok(NULL, ",");
Expand Down
9 changes: 4 additions & 5 deletions src/match.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,11 @@ list_update_t component_update(component_data_t *a, component_data_t *b)
if (strcmp(b->release_date, a->release_date) < 0)
return LIST_ITEM_UPDATE;
else
{
scanlog("--- Componen already exist: %s---\n", b->component);
component_data_free(b);
return LIST_ITEM_FOUND;
}
}
else
return LIST_ITEM_NOT_FOUND;
Expand Down Expand Up @@ -392,11 +396,6 @@ bool add_component_from_urlid(component_list_t *component_list, uint8_t *url_id,
else
scanlog("component accepted: %s - pathrank: %d\n", new_comp->purls[0], new_comp->path_rank);
}
else if (debug_on)
{
scanlog("--- Componen already exist: %s---\n", new_comp->component);
}

}
else
{
Expand Down
19 changes: 9 additions & 10 deletions src/quality.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ const char *quality_sources[] = {"best_practices"};
bool print_quality_item(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *data, uint32_t datalen, int iteration, void *ptr)
{

match_data_t * match = (match_data_t*) ptr;
char *CSV = (char*) data;
char ** out = ptr;
char *csv = (char*) data;
char *source = calloc(MAX_JSON_VALUE_LEN, 1);
char *quality = calloc(MAX_JSON_VALUE_LEN, 1);

extract_csv(source, CSV, 1, MAX_JSON_VALUE_LEN);
extract_csv(quality, CSV, 2, MAX_JSON_VALUE_LEN);
extract_csv(source, csv, 1, MAX_JSON_VALUE_LEN);
extract_csv(quality, csv, 2, MAX_JSON_VALUE_LEN);

int src = atoi(source);

Expand All @@ -85,7 +85,7 @@ bool print_quality_item(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *d
len += sprintf(result+len,"\"score\": \"%s\",", quality);
len += sprintf(result+len,"\"source\": \"%s\"", quality_sources[atoi(source)]);
len += sprintf(result+len,"}");
match->quality_text = strdup(result);
*out = strdup(result);
}


Expand All @@ -105,17 +105,16 @@ void print_quality(match_data_t * match)
return;

char result[MAX_FIELD_LN] = "\0";
match->quality_text = NULL;
char * aux = NULL;

sprintf(result,"\"quality\": [");


ldb_fetch_recordset(NULL, oss_quality, match->file_md5, false, print_quality_item, match);
ldb_fetch_recordset(NULL, oss_quality, match->file_md5, false, print_quality_item, &aux);

char * aux = NULL;
asprintf(&aux, "%s%s]", result, match->quality_text ? match->quality_text : "");
free(match->quality_text);
match->quality_text = aux;
asprintf(&match->quality_text, "%s%s]", result, aux ? aux : "");
free(aux);

}

0 comments on commit 8a28395

Please sign in to comment.