Skip to content

Commit

Permalink
Merge pull request #96 from marktwtn/fix-invalid-mem-operation
Browse files Browse the repository at this point in the history
Fix memory corruption
  • Loading branch information
jserv committed Feb 2, 2019
2 parents 0104c42 + fa15b32 commit ee0804a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/dcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void dcurl_destroy()
list_for_each(p, &IMPL_LIST) {
impl = list_entry(p, ImplContext, list);
destroyImplContext(impl);
list_del(p);
}
}

Expand Down
40 changes: 22 additions & 18 deletions tests/test-dcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "common.h"
#include "dcurl.h"

#define LOOP_MAX 5

int main()
{
char *trytes =
Expand Down Expand Up @@ -47,27 +49,29 @@ int main()

int mwm = 9;

/* test dcurl Implementation with mwm = 9 */
dcurl_init();
int8_t *ret_trytes = dcurl_entry((int8_t *) trytes, mwm, 0);
assert(ret_trytes);
dcurl_destroy();
for (int loop_count = 0; loop_count < LOOP_MAX; loop_count++) {
/* test dcurl Implementation with mwm = 9 */
dcurl_init();
int8_t *ret_trytes = dcurl_entry((int8_t *) trytes, mwm, 0);
assert(ret_trytes);
dcurl_destroy();

Trytes_t *trytes_t = initTrytes(ret_trytes, 2673);
assert(trytes_t);
Trytes_t *hash_trytes = hashTrytes(trytes_t);
assert(hash_trytes);
Trytes_t *trytes_t = initTrytes(ret_trytes, 2673);
assert(trytes_t);
Trytes_t *hash_trytes = hashTrytes(trytes_t);
assert(hash_trytes);

/* Validation */
Trits_t *ret_trits = trits_from_trytes(hash_trytes);
for (int i = 243 - 1; i >= 243 - mwm; i--) {
assert(ret_trits->data[i] == 0);
}
/* Validation */
Trits_t *ret_trits = trits_from_trytes(hash_trytes);
for (int i = 243 - 1; i >= 243 - mwm; i--) {
assert(ret_trits->data[i] == 0);
}

free(ret_trytes);
freeTrobject(trytes_t);
freeTrobject(hash_trytes);
freeTrobject(ret_trits);
free(ret_trytes);
freeTrobject(trytes_t);
freeTrobject(hash_trytes);
freeTrobject(ret_trits);
}

return 0;
}

0 comments on commit ee0804a

Please sign in to comment.