Skip to content

Commit

Permalink
Leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdremov committed Mar 17, 2021
1 parent 7960316 commit fcee09f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ project(CoRoutines C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_C_FLAGS_DEBUG "-g -O1 -fsanitize=address -fsanitize-address-use-after-scope ")
set(CMAKE_C_FLAGS_DEBUG "-g3")
set(CMAKE_C_FLAGS_RELEASE "-O3")

include_directories(.)
Expand Down
13 changes: 6 additions & 7 deletions src/coSort.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "stackArrays.h"
#include <string.h>

#define STACK_SIZE (1024 * 1024)
#define STACK_SIZE (SIGSTKSZ)
#define MICDIV 1000000
static CoPlanner planner;

Expand Down Expand Up @@ -77,6 +77,7 @@ int main(int argc, const char **argv) {

if (res.array)
free(res.array);
free(mergeStack.items);
fclose(outFile);
CoPlanner_destroy(&planner);
return 0;
Expand Down Expand Up @@ -130,7 +131,7 @@ void fileInputNumbers(ContextData *nowData, stack *input, int id) {
rewind(nowData->userData.file);
CoPlanner_rollIfLatency(&planner);

char *fileRead = malloc(size + 1);
char *fileRead = malloc(size + 2);

if (!fileRead) {
printf("Error on malloc in coroutine %d", id);
Expand Down Expand Up @@ -289,6 +290,8 @@ void CoPlanner_fire(CoPlanner *this) {

bool CoPlanner_roll(CoPlanner *this) {
CoPlanner_addCoElapsed(this);
if (this->now >= this->count)
return false;
ucontext_t *enterC = &this->contexts[this->now];
this->now = CoPlanner_nextAvailable(this);
if (this->now >= this->count)
Expand All @@ -306,11 +309,7 @@ void CoPlanner_swapToNowFrom(CoPlanner *this, ucontext_t *enterC) {

bool CoPlanner_rollIfLatency(CoPlanner *this) {
struct timeval elapsed = CoPlanner_elapsed(this);
if (elapsed.tv_sec > this->latencyByN.tv_sec)
return CoPlanner_roll(this);
else if (elapsed.tv_sec < this->latencyByN.tv_sec)
return false;
else if (elapsed.tv_usec >= this->latencyByN.tv_usec)
if (elapsed.tv_sec > this->latencyByN.tv_sec || (elapsed.tv_sec == this->latencyByN.tv_sec && elapsed.tv_usec >= this->latencyByN.tv_usec))
return CoPlanner_roll(this);
return false;
}
Expand Down

0 comments on commit fcee09f

Please sign in to comment.