Skip to content

Commit

Permalink
Merge pull request #114 from Kmannth/master
Browse files Browse the repository at this point in the history
2 Memory related defensive patches for GKL.
  • Loading branch information
Kmannth authored Aug 26, 2020
2 parents 26fa84f + 990510c commit 97f3889
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
10 changes: 9 additions & 1 deletion src/main/native/compression/IntelDeflater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,25 @@ JNIEXPORT void JNICALL Java_com_intel_gkl_compression_IntelDeflater_generateHuff

jbyte* input = (jbyte*)env->GetPrimitiveArrayCritical(inputBuffer, 0);

struct isal_huff_histogram *histogram;
struct isal_huff_histogram *histogram = (struct isal_huff_histogram *) malloc(sizeof(*histogram));
struct isal_hufftables *hufftables_custom;

if (histogram == NULL) {
DBG ("Malloc failed out of memory");
return;
}

memset(histogram, 0, sizeof(isal_huff_histogram));
isal_update_histogram((unsigned char*)input, 64*1024, histogram);
isal_create_hufftables(hufftables_custom, histogram);
lz_stream->hufftables = hufftables_custom;

env->SetLongField(obj, FID_lz_stream, (jlong)lz_stream);
env->ReleasePrimitiveArrayCritical(inputBuffer, input, 0);

free(histogram);
}

}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/main/native/smithwaterman/IntelSmithWaterman.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ JNIEXPORT jint JNICALL Java_com_intel_gkl_smithwaterman_IntelSmithWaterman_align
jbyte* alternate = (jbyte*)env->GetPrimitiveArrayCritical(alt, 0);
jbyte* cigarArray = (jbyte*)env->GetPrimitiveArrayCritical(cigar, 0);

if (reference == NULL | alternate == NULL | cigarArray == NULL) {
DBG("GetPrimitiveArrayCritical failed from JAVA unable to contiune");
return -1;
}

jint count = 0;
jint offset = 0;

Expand Down
30 changes: 18 additions & 12 deletions src/main/native/smithwaterman/PairWiseSW.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,21 @@ int32_t CONCAT(runSWOnePairBT_,SIMD_ENGINE)(int32_t match, int32_t mismatch, int



int32_t w_match = match;
int32_t w_mismatch = mismatch;
int32_t w_open = open;
int32_t w_extend = extend;

int32_t *E_ = (int32_t *)_mm_malloc((6 * (MAX_SEQ_LEN+ AVX_LENGTH)) * sizeof(int32_t), 64);
int16_t *backTrack_ = (int16_t *)_mm_malloc((2 * MAX_SEQ_LEN * MAX_SEQ_LEN + 2 * AVX_LENGTH) * sizeof(int16_t), 64);
int16_t *cigarBuf_ = (int16_t *)_mm_malloc(4 * MAX_SEQ_LEN * sizeof(int16_t), 64);

int32_t w_match = match;
int32_t w_mismatch = mismatch;
int32_t w_open = open;
int32_t w_extend = extend;

int32_t *E_ = (int32_t *)_mm_malloc((6 * (MAX_SEQ_LEN+ AVX_LENGTH)) * sizeof(int32_t), 64);
int16_t *backTrack_ = (int16_t *)_mm_malloc((2 * MAX_SEQ_LEN * MAX_SEQ_LEN + 2 * AVX_LENGTH) * sizeof(int16_t), 64);
int16_t *cigarBuf_ = (int16_t *)_mm_malloc(4 * MAX_SEQ_LEN * sizeof(int16_t), 64);

if (E_ == NULL | backTrack_ == NULL | cigarBuf_ == NULL) {
_mm_free(E_);
_mm_free(backTrack_);
_mm_free(cigarBuf_);
return -1;
}

SeqPair p;
p.seq1 = seq1;
Expand All @@ -442,8 +448,8 @@ int32_t CONCAT(runSWOnePairBT_,SIMD_ENGINE)(int32_t match, int32_t mismatch, int

(*cigarCount) = p.cigarCount;

free(E_);
free(backTrack_);
free(cigarBuf_);
_mm_free(E_);
_mm_free(backTrack_);
_mm_free(cigarBuf_);
return p.alignmentOffset;
}

0 comments on commit 97f3889

Please sign in to comment.