Skip to content

Commit 2cd55a3

Browse files
hotfix: correct minor bug in selection logic. Fix license report memory issue (#95)
1 parent 76e75ef commit 2cd55a3

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

inc/scanoss.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
#define WFP_LN 4
4040
#define WFP_REC_LN 18
4141

42+
#define SCANOSS_VERSION "5.4.15"
43+
4244
/* Log files */
43-
#define SCANOSS_VERSION "5.4.14"
4445
#define SCAN_LOG "/tmp/scanoss_scan.log"
4546
#define MAP_DUMP "/tmp/scanoss_map.dump"
4647
#define SLOW_QUERY_LOG "/tmp/scanoss_slow_query.log"

src/license.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void print_licenses(component_data_t *comp)
395395
}
396396

397397
/* Open licenses structure */
398-
char result[MAX_FIELD_LN * 10] = "\0";
398+
char * result = calloc(MAX_FIELD_LN * 100, 1);
399399
int len = 0;
400400

401401
len += sprintf(result + len, "\"licenses\": [");
@@ -426,4 +426,5 @@ void print_licenses(component_data_t *comp)
426426

427427
asprintf(&comp->license_text, "%s]", result);
428428
free(license_result.license_by_type);
429+
free(result);
429430
}

src/match.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,22 +351,29 @@ static bool component_hint_date_comparation(component_data_t *a, component_data_
351351
return true;
352352
}
353353

354-
if (!purl_vendor_component_check(a) && purl_vendor_component_check(b))
355-
{
356-
scanlog("Component prefered by vendor+component=purl\n");
357-
return true;
358-
}
359354
//Look for available health information
360355
print_health(a);
361356
print_health(b);
362357
int health_a = a->health_stats[0] + a->health_stats[2]; //add forks and watchers
363358
int health_b = b->health_stats[0] + b->health_stats[2];
364359

360+
365361
if (health_b > health_a)
366362
{
367363
scanlog("Component prefered by health: %s = %d vs %s = %d\n", b->purls[0], health_b, a->purls[0], health_a);
368364
return true;
369365
}
366+
else if (health_a > health_b)
367+
{
368+
return false;
369+
}
370+
371+
372+
if (!purl_vendor_component_check(a) && purl_vendor_component_check(b))
373+
{
374+
scanlog("Component %s prefered over %s by vendor+component=purl\n", b->purls[0], a->purls[0]);
375+
return true;
376+
}
370377

371378
if (!a->purls_md5[0] && a->purls[0])
372379
{
@@ -383,10 +390,16 @@ static bool component_hint_date_comparation(component_data_t *a, component_data_
383390
}
384391

385392
if ((!a->age && b->age) || b->age > a->age)
393+
{
394+
scanlog("Component %s prefered over %s by purl date\n", b->purls[0], a->purls[0]);
386395
return true;
396+
}
387397

388398
if (b->age == a->age && !strcmp(a->component, b->component) && strcmp(a->version, b->version) > 0)
399+
{
400+
scanlog("Component %s prefered over %s by version\n", b->purls[0], a->purls[0]);
389401
return true;
402+
}
390403
}
391404
/*select the oldest release date */
392405
if (strcmp(b->release_date, a->release_date) < 0)

src/quality.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ bool print_quality_item(uint8_t *key, uint8_t *subkey, int subkey_ln, uint8_t *d
5757
{
5858

5959
match_data_t * match = (match_data_t*) ptr;
60-
char *CSV = (char*) data;
60+
char *CSV = strdup((char*) data);
61+
CSV[datalen] = '\0';
6162
char *source = calloc(MAX_JSON_VALUE_LEN, 1);
6263
char *quality = calloc(MAX_JSON_VALUE_LEN, 1);
6364

6465
extract_csv(source, CSV, 1, MAX_JSON_VALUE_LEN);
6566
extract_csv(quality, CSV, 2, MAX_JSON_VALUE_LEN);
66-
67+
free(CSV);
6768
int src = atoi(source);
6869

6970
scanlog("Fetched quality %s\n", quality);

src/url.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ bool purl_vendor_component_check(component_data_t * component)
418418
if (a && b)
419419
{
420420
if (a == b)
421-
return false;
422-
return true;
421+
return true;
422+
return false;
423423
}
424424
return false;
425425
}

0 commit comments

Comments
 (0)