Windows XP memory leak ??? [innocent newbie :)]

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Windows XP memory leak ??? [innocent newbie :)]

sam copydata

I'm working on a threaded project under Linux & Windows. This project
is almost developed under Linux and then ported to windows. When we
tried to check memory stability under windows we found some leaks
while there was none under Linux.

When program runs, it grows up in memory by 4 KB blocks only under
windows XP (home or pro version) but it do not moves under windows
server 2003 or under Linux.

After many tests i isolated this code which reproduce the leak of memory :

//////////////////////////////////////////////// main.cpp
#include <iostream>
#include <pthread.h>

using namespace std;

#ifdef WIN32
# define usleep Sleep
# include "crtdbg.h"
# include <Windows.h>

typedef struct toto_s toto_t;

struct toto_s
  int ok;

void    *testthread(void *a)
  toto_t *test;

  test = (toto_t *)a;
  cout << "thread créé" << endl;
   test->ok = 1;

  return NULL;

int main()
  pthread_t    thread;
  toto_t    *data;

  data = (toto_t *)malloc(sizeof(toto_t));
  data->ok = 0;
  for (int i = 100000; i; i--)
      if (pthread_create(&thread, NULL, testthread, (void *)data))
            cout << "erreur : impossible de créer le thread" << endl;
            return -1;
//       testthread(data);
      cout << "thread " << 100000 - i << " créé" << endl;
      while (!data->ok)
      data->ok = 0;

  return 0;

//////////////////////////////////////////////// End of main.cpp

I compile this code with prebuild version of pthread 2.7.0 or 2.8.0
with the same results.
 I tried to do it in many other ways always with the same memory leak.

If someone have an idea, it would be very welcome, I'm on this since 3 days. :(