Suggested by Nick Clifton.
---
docs/libnbd.pod | 10 ++++++++++
generator/generator | 1 +
2 files changed, 11 insertions(+)
diff --git a/docs/libnbd.pod b/docs/libnbd.pod
index 6a329d6..b42d000 100644
--- a/docs/libnbd.pod
+++ b/docs/libnbd.pod
@@ -13,6 +13,7 @@ libnbd - network block device (NBD) client library in userspace
nbd_connect_tcp (nbd, "server.example.com", "nbd") == -1 ||
nbd_pread (nbd, buf, sizeof buf, 0, 0) == -1)
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
nbd_close (nbd);
@@ -80,10 +81,12 @@ Create a handle and connect to the server:
nbd = nbd_create ();
if (!nbd) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
if (nbd_connect_tcp (nbd, "server.example.com", "nbd") == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
@@ -93,6 +96,7 @@ Read the first sector (512 bytes) from the NBD export:
if (nbd_pread (nbd, buf, sizeof buf, 0, 0) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
@@ -125,6 +129,7 @@ example the asynchronous variant of C<nbd_pread> is:
cookie = nbd_aio_pread (nbd, buf, sizeof buf, 0, 0);
if (cookie == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
@@ -222,6 +227,7 @@ As with the high level API, it all starts by creating a handle:
nbd = nbd_create ();
if (nbd == NULL) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
@@ -237,11 +243,13 @@ until the connection becomes ready:
then ... */
if (nbd_aio_connect (nbd, &addr, len) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
while (!nbd_aio_is_ready (nbd)) {
if (nbd_poll (nbd, -1) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
}
@@ -256,11 +264,13 @@ command has completed:
cookie = nbd_aio_pread (nbd, buf, sizeof buf, offset, 0)
if (cookie == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
while (!nbd_aio_command_completed (nbd, cookie)) {
if (nbd_poll (nbd, -1) == -1) {
fprintf (stderr, "%s\n", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
}
diff --git a/generator/generator b/generator/generator
index 6621bee..29d0373 100755
--- a/generator/generator
+++ b/generator/generator
@@ -3773,6 +3773,7 @@ libnbd-api - libnbd C API
nbd_connect_tcp (nbd, \"server.example.com\", \"nbd\") == -1 ||
nbd_pread (nbd, buf, sizeof buf, 0, 0) == -1)
fprintf (stderr, \"%%s\\n\", nbd_get_error ());
+ nbd_close (nbd);
exit (EXIT_FAILURE);
}
nbd_close (nbd);
--
2.22.0