* It's reasonable to allocate memory after checking
  _POSIX_SEMAPHORES.
  Allocate 'buf' on the stack to avoid the problem.

* remove meaningless printf()

Signed-off-by: Wei,Jiangang <weijg.f...@cn.fujitsu.com>
---
 .../functional/semaphores/sem_conpro.c                 | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c 
b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
index f5f1abf..2fb9890 100644
--- a/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
+++ b/testcases/open_posix_testsuite/functional/semaphores/sem_conpro.c
@@ -100,34 +100,32 @@ int main(int argc, char *argv[])
        int occupied_value = BUF_SIZE;
        int empty_value = 0;
        int lock_value = 1;
-       buf_t *buf;
+       buf_t buf;
        pthread_t con, pro;
-       buf = malloc(sizeof(buf_t));
 
 #ifndef  _POSIX_SEMAPHORES
        printf("_POSIX_SEMAPHORES is not defined \n");
        return PTS_UNRESOLVED;
 #endif
-       if (-1 == sem_init(&(buf->occupied), shared, occupied_value)) {
+       if (-1 == sem_init(&buf.occupied, shared, occupied_value)) {
                perror("sem_init didn't return success \n");
-               printf("hello \n");
                return PTS_UNRESOLVED;
        }
-       if (-1 == sem_init(&buf->empty, shared, empty_value)) {
+       if (-1 == sem_init(&buf.empty, shared, empty_value)) {
                perror("sem_init didn't return success \n");
                return PTS_UNRESOLVED;
        }
-       if (-1 == sem_init(&buf->lock, shared, lock_value)) {
+       if (-1 == sem_init(&buf.lock, shared, lock_value)) {
                perror("sem_init didn't return success \n");
                return PTS_UNRESOLVED;
        }
        in = out = 0;
 
-       pthread_create(&con, NULL, (void *)consumer, (void *)buf);
-       pthread_create(&pro, NULL, (void *)producer, (void *)buf);
+       pthread_create(&con, NULL, (void *)consumer, (void *)&buf);
+       pthread_create(&pro, NULL, (void *)producer, (void *)&buf);
        pthread_join(con, NULL);
        pthread_join(pro, NULL);
-       sem_destroy(&buf->occupied);
-       sem_destroy(&buf->empty);
+       sem_destroy(&buf.occupied);
+       sem_destroy(&buf.empty);
        return PTS_PASS;
 }
-- 
1.9.3


------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to