Jan Willamowius
2019-04-21 683e25de59b6b7307a9654b17a4c784e8897d33a
fix memory leaks on error
2个文件已修改
19 ■■■■■ 已修改文件
src/library/os/os-linux.c 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/pc-identifiers.c 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/os-linux.c
@@ -65,11 +65,11 @@
    struct mntent *ent;
    int maxDrives, currentDrive, i, drive_found;
    __ino64_t *statDrives;
    DiskInfo *tmpDrives;
    FILE *aFile;
    DIR *disk_by_uuid_dir, *disk_by_label;
    struct dirent *dir;
    __ino64_t *statDrives = NULL;
    DiskInfo *tmpDrives = NULL;
    FILE *aFile = NULL;
    DIR *disk_by_uuid_dir = NULL, *disk_by_label = NULL;
    struct dirent *dir = NULL;
    FUNCTION_RETURN result;
    if (diskInfos != NULL) {
@@ -87,6 +87,8 @@
    aFile = setmntent("/proc/mounts", "r");
    if (aFile == NULL) {
        /*proc not mounted*/
        free(tmpDrives);
        free(statDrives);
        return FUNC_RET_ERROR;
    }
src/library/pc-identifiers.c
@@ -281,7 +281,7 @@
        PcSignature pc_identifier_out) {
    //TODO base62 encoding, now uses base64
    PcIdentifier concat_identifiers[2];
    char* b64_data;
    char* b64_data = NULL;
    int b64_size = 0;
    size_t concatIdentifiersSize = sizeof(PcIdentifier) * 2;
    //concat_identifiers = (PcIdentifier *) malloc(concatIdentifiersSize);
@@ -289,6 +289,7 @@
    memcpy(&concat_identifiers[1], identifier2, sizeof(PcIdentifier));
    b64_data = base64(concat_identifiers, concatIdentifiersSize, &b64_size);
    if (b64_size > sizeof(PcSignature)) {
        free(b64_data);
        return FUNC_RET_BUFFER_TOO_SMALL;
    }
    sprintf(pc_identifier_out, "%.4s-%.4s-%.4s-%.4s", &b64_data[0],
@@ -345,7 +346,7 @@
        PcIdentifier identifier2_out, PcSignature pc_signature_in) {
    //TODO base62 encoding, now uses base64
    unsigned char * concat_identifiers;
    unsigned char * concat_identifiers = NULL;
    char base64ids[17];
    int identifiers_size;
@@ -353,6 +354,7 @@
            &base64ids[8], &base64ids[12]);
    concat_identifiers = unbase64(base64ids, 16, &identifiers_size);
    if (identifiers_size > sizeof(PcIdentifier) * 2) {
        free(concat_identifiers);
        return FUNC_RET_BUFFER_TOO_SMALL;
    }
    memcpy(identifier1_out, concat_identifiers, sizeof(PcIdentifier));
@@ -386,6 +388,7 @@
    for (i = 0; i < 2; i++) {
        current_strategy_id = strategy_from_pc_id(user_identifiers[i]);
        if (current_strategy_id == STRATEGY_UNKNOWN) {
            free(calculated_identifiers);
            return LICENSE_MALFORMED;
        }
        if (current_strategy_id != previous_strategy_id) {