Skip to content

Commit

Permalink
free bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarybednarz committed Jan 31, 2021
1 parent 9b6ba2a commit 08578c0
Show file tree
Hide file tree
Showing 16 changed files with 12 additions and 15 deletions.
7 changes: 5 additions & 2 deletions actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int actor_push_message(actor_t* actor, message_t* message) {
}

if (queue_push(actor->message_queue, message) != 0) {
free(message);
if (pthread_mutex_unlock(&(actor->lock)) != 0) {
syserr("mutex unlock");
}
Expand All @@ -69,7 +70,7 @@ int actor_push_message(actor_t* actor, message_t* message) {
}

if (pthread_mutex_unlock(&(actor->lock))) {
return -1;
syserr("mutex unlock");
}
return 0;
}
Expand All @@ -83,7 +84,9 @@ void handle_spawn(actor_t* actor, message_t* message) {
return;
}

actor_system_insert(actor->a_system, new_actor);
if (actor_system_insert(actor->a_system, new_actor) == -1) {
return;
}

message_t hello_message = {
.message_type = MSG_HELLO,
Expand Down
1 change: 1 addition & 0 deletions actor_system.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int actor_system_insert(actor_system_t* a_system, actor_t* actor) {
if (pthread_mutex_lock(&(a_system->lock)) != 0) {
return -1;
}

if (queue_push(a_system->actors, actor) != 0) {
pthread_mutex_unlock(&(a_system->lock));
return -1;
Expand Down
4 changes: 1 addition & 3 deletions cacti.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ void actor_system_join(actor_id_t actor) {
int send_message(actor_id_t actor_id, message_t message) {
actor_t* actor = actor_system_find(&a_system, actor_id);

if (rand() % 300000 == 1)
printf("send_message: from actor %lu message = %lu actor_id = %lu\n", actor_id_self(), message.message_type, actor_id);

// no actor with that id in system
if (actor == NULL) {
return -2;
Expand All @@ -92,6 +89,7 @@ int send_message(actor_id_t actor_id, message_t message) {
message_copy->nbytes = message.nbytes;

if (actor_push_message(actor, message_copy) != 0) {
free(message_copy);
fprintf(stderr, "send_message: error while pushing message, queue full\n");
return -3;
}
Expand Down
4 changes: 2 additions & 2 deletions cacti.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ typedef long message_type_t;
#define MSG_HELLO (message_type_t)0x0

#ifndef ACTOR_QUEUE_LIMIT
#define ACTOR_QUEUE_LIMIT 1024
#define ACTOR_QUEUE_LIMIT 1000024
#endif

#ifndef CAST_LIMIT
//#define CAST_LIMIT 1048576
#define CAST_LIMIT 100
#define CAST_LIMIT 10
#endif

#ifndef POOL_SIZE
Expand Down
4 changes: 0 additions & 4 deletions cmake-build-debug/CMakeFiles/cacti.dir/C.includecache
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ actor_system.h
cacti.h
/home/cezary/Studia/PW/pw2-C/cacti.h

/home/cezary/Studia/PW/pw2-C/cacti.c
cacti.h
/home/cezary/Studia/PW/pw2-C/cacti.h

/home/cezary/Studia/PW/pw2-C/cacti.h
stddef.h
-
Expand Down
Binary file modified cmake-build-debug/CMakeFiles/cacti.dir/actor.c.o
Binary file not shown.
Binary file modified cmake-build-debug/CMakeFiles/cacti.dir/actor_system.c.o
Binary file not shown.
Binary file modified cmake-build-debug/CMakeFiles/cacti.dir/cacti.c.o
Binary file not shown.
Binary file modified cmake-build-debug/CMakeFiles/chaos.dir/test/chaos.cpp.o
Binary file not shown.
Binary file modified cmake-build-debug/CMakeFiles/macierz.dir/macierz.c.o
Binary file not shown.
4 changes: 2 additions & 2 deletions cmake-build-debug/Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Start testing: Jan 31 21:12 CET
Start testing: Jan 31 22:39 CET
----------------------------------------------------------
End testing: Jan 31 21:12 CET
End testing: Jan 31 22:39 CET
Binary file modified cmake-build-debug/chaos
Binary file not shown.
Binary file modified cmake-build-debug/libcacti.a
Binary file not shown.
Binary file modified cmake-build-debug/macierz
Binary file not shown.
Binary file modified cmake-build-debug/silnia
Binary file not shown.
3 changes: 1 addition & 2 deletions test/chaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void do_chaos(void**, size_t, void*) {

int main() {
actor_id_t initial;
for (long int i = 0; i < 1000000; i++) {
for (long int i = 0; i < 1; i++) {
printf("Loop #%li\n", i);

max_actor_id = 0;
Expand All @@ -70,7 +70,6 @@ int main() {
printf("initial: %d\n", ret);
if (ret < 0)
abort();
printf("JOINING!\n");
actor_system_join(initial);

printf("-> Complete! Max actor id: %li\n", max_actor_id.load());
Expand Down

0 comments on commit 08578c0

Please sign in to comment.