Skip to content

Commit

Permalink
examples: call freenect_shutdown() on exit
Browse files Browse the repository at this point in the history
This is mostly useful when using tools like valgrind, which may report
possibly lost memory even if the operating systems is going to get it
back anyway on the actual process exit.

Signed-off-by: Antonio Ospite <ospite@studenti.unina.it>
  • Loading branch information
Antonio Ospite authored and zarvox committed Mar 10, 2012
1 parent 071f51e commit 6e6015c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
6 changes: 5 additions & 1 deletion examples/glview.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,21 @@ int main(int argc, char **argv)
if (argc > 1)
user_device_number = atoi(argv[1]);

if (nr_devices < 1)
if (nr_devices < 1) {
freenect_shutdown(f_ctx);
return 1;
}

if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
printf("Could not open device\n");
freenect_shutdown(f_ctx);
return 1;
}

res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
if (res) {
printf("pthread_create failed\n");
freenect_shutdown(f_ctx);
return 1;
}

Expand Down
6 changes: 5 additions & 1 deletion examples/hiview.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,17 +445,21 @@ int main(int argc, char **argv)
if (argc > 1)
user_device_number = atoi(argv[1]);

if (nr_devices < 1)
if (nr_devices < 1) {
freenect_shutdown(f_ctx);
return 1;
}

if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
printf("Could not open device\n");
freenect_shutdown(f_ctx);
return 1;
}

res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
if (res) {
printf("pthread_create failed\n");
freenect_shutdown(f_ctx);
return 1;
}

Expand Down
6 changes: 5 additions & 1 deletion examples/micview.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,15 @@ int main(int argc, char** argv) {

int nr_devices = freenect_num_devices (f_ctx);
printf ("Number of devices found: %d\n", nr_devices);
if (nr_devices < 1)
if (nr_devices < 1) {
freenect_shutdown(f_ctx);
return 1;
}

int user_device_number = 0;
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
printf("Could not open device\n");
freenect_shutdown(f_ctx);
return 1;
}

Expand All @@ -188,6 +191,7 @@ int main(int argc, char** argv) {
int res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
if (res) {
printf("pthread_create failed\n");
freenect_shutdown(f_ctx);
return 1;
}
printf("This is the libfreenect microphone waveform viewer. Press 'q' to quit or spacebar to pause/unpause the view.\n");
Expand Down
6 changes: 5 additions & 1 deletion examples/regview.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,17 +363,21 @@ int main(int argc, char **argv)
if (argc > 1)
user_device_number = atoi(argv[1]);

if (nr_devices < 1)
if (nr_devices < 1) {
freenect_shutdown(f_ctx);
return 1;
}

if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
printf("Could not open device\n");
freenect_shutdown(f_ctx);
return 1;
}

res = pthread_create(&freenect_thread, NULL, freenect_threadfunc, NULL);
if (res) {
printf("pthread_create failed\n");
freenect_shutdown(f_ctx);
return 1;
}

Expand Down
6 changes: 5 additions & 1 deletion examples/wavrecord.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,15 @@ int main(int argc, char** argv) {

int nr_devices = freenect_num_devices (f_ctx);
printf ("Number of devices found: %d\n", nr_devices);
if (nr_devices < 1)
if (nr_devices < 1) {
freenect_shutdown(f_ctx);
return 1;
}

int user_device_number = 0;
if (freenect_open_device(f_ctx, &f_dev, user_device_number) < 0) {
printf("Could not open device\n");
freenect_shutdown(f_ctx);
return 1;
}

Expand Down Expand Up @@ -135,5 +138,6 @@ int main(int argc, char** argv) {
fclose(state.logfiles[i]);
}

freenect_shutdown(f_ctx);
return 0;
}

0 comments on commit 6e6015c

Please sign in to comment.