From: neo23 Date: Fri, 16 Aug 2002 17:41:04 +0000 (+0000) Subject: Applied a patch from Dietmar Petras that plugs some X-Git-Tag: 0.10.0~1000 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1bc0858080a41ed364550a5590f3a19f5aa6fae6;p=check Applied a patch from Dietmar Petras that plugs some memory leaks. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@148 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/check/src/check.c b/check/src/check.c index 3a88330..1fc5b07 100644 --- a/check/src/check.c +++ b/check/src/check.c @@ -57,7 +57,8 @@ void suite_free (Suite *s) List *l; if (s == NULL) return; - for (l = s->tclst; !list_at_end(l); list_advance (l)) { + l = s->tclst; + for (list_front(l); !list_at_end(l); list_advance (l)) { tcase_free (list_val(l)); } list_free (s->tclst); diff --git a/check/src/check_msg.c b/check/src/check_msg.c index 3559434..6d4f95b 100644 --- a/check/src/check_msg.c +++ b/check/src/check_msg.c @@ -33,11 +33,6 @@ #include "check_msg.h" #include "check_pack.h" -struct MsgKey -{ - int key; -}; - typedef struct Pipe { int sendfd; @@ -54,17 +49,17 @@ typedef struct PipeEntry List *plst = NULL; -static PipeEntry *get_pe_by_key(MsgKey *key); -static Pipe *get_pipe_by_key(MsgKey *key); -static MsgKey *get_setup_key (void); +static PipeEntry *get_pe_by_key(MsgKey key); +static Pipe *get_pipe_by_key(MsgKey key); +static MsgKey get_setup_key (void); static void setup_pipe (Pipe *p); -static void setup_messaging_with_key (MsgKey *key); -static void teardown_messaging_with_key (MsgKey *key); +static void setup_messaging_with_key (MsgKey key); +static void teardown_messaging_with_key (MsgKey key); static TestResult *construct_test_result (RcvMsg *rmsg, int waserror); static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx, RcvMsg *rmsg); -void send_failure_info (MsgKey *key, const char *msg) +void send_failure_info (MsgKey key, const char *msg) { FailMsg fmsg; Pipe *p; @@ -76,7 +71,7 @@ void send_failure_info (MsgKey *key, const char *msg) ppack (p->sendfd, CK_MSG_FAIL, (CheckMsg *) &fmsg); } -void send_loc_info (MsgKey *key, const char * file, int line) +void send_loc_info (MsgKey key, const char * file, int line) { LocMsg lmsg; Pipe *p; @@ -89,7 +84,7 @@ void send_loc_info (MsgKey *key, const char * file, int line) ppack (p->sendfd, CK_MSG_LOC, (CheckMsg *) &lmsg); } -void send_ctx_info (MsgKey *key,enum ck_result_ctx ctx) +void send_ctx_info (MsgKey key,enum ck_result_ctx ctx) { CtxMsg cmsg; Pipe *p; @@ -102,10 +97,11 @@ void send_ctx_info (MsgKey *key,enum ck_result_ctx ctx) ppack (p->sendfd, CK_MSG_CTX, (CheckMsg *) &cmsg); } -TestResult *receive_test_result (MsgKey *key, int waserror) +TestResult *receive_test_result (MsgKey key, int waserror) { Pipe *p; RcvMsg *rmsg; + TestResult *result; p = get_pipe_by_key (key); if (p == NULL) @@ -115,7 +111,9 @@ TestResult *receive_test_result (MsgKey *key, int waserror) close (p->recvfd); setup_pipe (p); - return construct_test_result (rmsg, waserror); + result = construct_test_result (rmsg, waserror); + rcvmsg_free(rmsg); + return result; } static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx, @@ -124,9 +122,13 @@ static void tr_set_loc_by_ctx (TestResult *tr, enum ck_result_ctx ctx, if (ctx == CK_CTX_TEST) { tr->file = rmsg->test_file; tr->line = rmsg->test_line; + rmsg->test_file = NULL; + rmsg->test_line = -1; } else { tr->file = rmsg->fixture_file; tr->line = rmsg->fixture_line; + rmsg->fixture_file = NULL; + rmsg->fixture_line = -1; } } @@ -142,6 +144,7 @@ static TestResult *construct_test_result (RcvMsg *rmsg, int waserror) if (rmsg->msg != NULL || waserror) { tr->ctx = rmsg->lastctx; tr->msg = rmsg->msg; + rmsg->msg = NULL; tr_set_loc_by_ctx (tr, rmsg->lastctx, rmsg); } else if (rmsg->lastctx == CK_CTX_SETUP) { tr->ctx = CK_CTX_SETUP; @@ -162,27 +165,27 @@ void setup_messaging (void) setup_messaging_with_key (get_recv_key()); } -MsgKey *get_send_key (void) +MsgKey get_send_key (void) { - MsgKey *key = emalloc (sizeof (MsgKey)); + MsgKey key; if (cur_fork_status () == CK_FORK) - key->key = getppid (); + key.key = getppid (); else - key->key = getpid (); + key.key = getpid (); return key; } -MsgKey *get_recv_key (void) +MsgKey get_recv_key (void) { - MsgKey *key = emalloc (sizeof (MsgKey)); + MsgKey key; - key->key = getpid (); + key.key = getpid (); return key; } -static MsgKey *get_setup_key (void) +static MsgKey get_setup_key (void) { return get_recv_key (); } @@ -198,10 +201,10 @@ void setup_test_messaging (void) setup_messaging_with_key (get_test_key ()); } -MsgKey *get_test_key (void) +MsgKey get_test_key (void) { - MsgKey *key = emalloc (sizeof (MsgKey)); - key->key = -1; + MsgKey key; + key.key = -1; return key; } @@ -211,13 +214,13 @@ void teardown_test_messaging (void) teardown_messaging_with_key (get_test_key ()); } -static PipeEntry *get_pe_by_key (MsgKey *key) +static PipeEntry *get_pe_by_key (MsgKey key) { PipeEntry *pe = NULL; for (list_front(plst); !list_at_end(plst); list_advance(plst)) { PipeEntry *p = list_val(plst); - if (p->key == key->key) { + if (p->key == key.key) { pe = p; break; } @@ -226,7 +229,7 @@ static PipeEntry *get_pe_by_key (MsgKey *key) return pe; } -static Pipe *get_pipe_by_key (MsgKey *key) +static Pipe *get_pipe_by_key (MsgKey key) { Pipe *pr = NULL; PipeEntry *pe = get_pe_by_key (key); @@ -261,7 +264,7 @@ static void setup_pipe (Pipe *p) fcntl (p->sendfd, F_SETFL, O_NONBLOCK); } -static void setup_messaging_with_key (MsgKey *key) +static void setup_messaging_with_key (MsgKey key) { PipeEntry *pe; @@ -272,7 +275,7 @@ static void setup_messaging_with_key (MsgKey *key) if (pe == NULL) { pe = emalloc (sizeof (PipeEntry)); pe->cur = 0; - pe->key = key->key; + pe->key = key.key; list_add_end (plst, pe); } if (pe->cur == 0) { @@ -287,7 +290,7 @@ static void setup_messaging_with_key (MsgKey *key) eprintf ("Only one nesting of suite runs supported", __FILE__, __LINE__); } -static void teardown_messaging_with_key (MsgKey *key) +static void teardown_messaging_with_key (MsgKey key) { PipeEntry *pe = get_pe_by_key (key); diff --git a/check/src/check_msg.h b/check/src/check_msg.h index cde7392..3ef66bb 100644 --- a/check/src/check_msg.h +++ b/check/src/check_msg.h @@ -22,24 +22,29 @@ #define CHECK_MSG_NEW_H +struct MsgKey +{ + int key; +}; + typedef struct MsgKey MsgKey; /* Functions implementing messaging during test runs */ -void send_failure_info (MsgKey *key, const char *msg); -void send_loc_info (MsgKey *key, const char *file, int line); -void send_ctx_info (MsgKey *key, enum ck_result_ctx ctx); +void send_failure_info (MsgKey key, const char *msg); +void send_loc_info (MsgKey key, const char *file, int line); +void send_ctx_info (MsgKey key, enum ck_result_ctx ctx); -TestResult *receive_test_result (MsgKey *key, int waserror); +TestResult *receive_test_result (MsgKey key, int waserror); void setup_messaging(void); -MsgKey *get_send_key(void); -MsgKey *get_recv_key(void); +MsgKey get_send_key(void); +MsgKey get_recv_key(void); void teardown_messaging(void); /* for testing only */ void setup_test_messaging(void); -MsgKey *get_test_key(void); +MsgKey get_test_key(void); void teardown_test_messaging(void); #endif /*CHECK_MSG_NEW_H */ diff --git a/check/src/check_pack.c b/check/src/check_pack.c index 908b5bb..c1c49a0 100644 --- a/check/src/check_pack.c +++ b/check/src/check_pack.c @@ -63,6 +63,7 @@ static int get_result (char *buf, RcvMsg *rmsg); static void rcvmsg_update_ctx (RcvMsg *rmsg, enum ck_result_ctx ctx); static void rcvmsg_update_loc (RcvMsg *rmsg, const char *file, int line); static RcvMsg *rcvmsg_create (void); +void rcvmsg_free (RcvMsg *rmsg); typedef int (*pfun) (char **, CheckMsg *); typedef void (*upfun) (char **, CheckMsg *); @@ -342,6 +343,14 @@ static RcvMsg *rcvmsg_create (void) return rmsg; } +void rcvmsg_free (RcvMsg *rmsg) +{ + if (rmsg->fixture_file!=NULL) free(rmsg->fixture_file); + if (rmsg->test_file!=NULL) free(rmsg->test_file); + if (rmsg->msg!=NULL) free(rmsg->msg); + free(rmsg); +} + static void rcvmsg_update_ctx (RcvMsg *rmsg, enum ck_result_ctx ctx) { if (rmsg->lastctx != -1) @@ -355,10 +364,12 @@ static void rcvmsg_update_loc (RcvMsg *rmsg, const char *file, int line) int flen = strlen(file); if (rmsg->lastctx == CK_CTX_TEST) { + if (rmsg->test_file!=NULL) free(rmsg->test_file); rmsg->test_line = line; rmsg->test_file = emalloc (flen + 1); strcpy (rmsg->test_file, file); } else { + if (rmsg->fixture_file!=NULL) free(rmsg->fixture_file); rmsg->fixture_line = line; rmsg->fixture_file = emalloc (flen + 1); strcpy (rmsg->fixture_file, file); diff --git a/check/src/check_pack.h b/check/src/check_pack.h index dd6c40d..3765216 100644 --- a/check/src/check_pack.h +++ b/check/src/check_pack.h @@ -62,6 +62,8 @@ typedef struct RcvMsg char *msg; } RcvMsg; +void rcvmsg_free (RcvMsg *rmsg); + int pack (enum ck_msg_type type, char **buf, CheckMsg *msg); int upack (char *buf, CheckMsg *msg, enum ck_msg_type *type);