diff options
-rw-r--r-- | documentation/cxx/hybrid/guide/index.xhtml | 29 | ||||
-rw-r--r-- | examples/cxx/hybrid/minimal/driver.cxx | 57 |
2 files changed, 78 insertions, 8 deletions
diff --git a/documentation/cxx/hybrid/guide/index.xhtml b/documentation/cxx/hybrid/guide/index.xhtml index 460e3b2..39d7e9b 100644 --- a/documentation/cxx/hybrid/guide/index.xhtml +++ b/documentation/cxx/hybrid/guide/index.xhtml @@ -1153,11 +1153,36 @@ main (int argc, char* argv[]) // Change the greeting phrase. // - h->greeting (strdupx ("Hi")); + char* str = strdupx ("Hi"); + + if (str == 0) + { + fprintf (stderr, "error: no memory\n"); + delete h; + return 1; + } + + h->greeting (str); // Add another entry to the name sequence. // - h->name ().push_back (strdupx ("mars")); + str = strdupx ("mars"); + + if (str == 0) + { + fprintf (stderr, "error: no memory\n"); + delete h; + return 1; + } + + if (h->name ().push_back (str) != 0) + { + // The sequence has already freed str. + // + fprintf (stderr, "error: no memory\n"); + delete h; + return 1; + } // Serialize. // diff --git a/examples/cxx/hybrid/minimal/driver.cxx b/examples/cxx/hybrid/minimal/driver.cxx index f23f308..38afd9a 100644 --- a/examples/cxx/hybrid/minimal/driver.cxx +++ b/examples/cxx/hybrid/minimal/driver.cxx @@ -175,13 +175,58 @@ main (int argc, char* argv[]) // Insert a new person. // { - person* p = new person; - p->first_name (strdupx ("Joe")); - p->last_name (strdupx ("Dirt")); - p->age (36); - p->gender (gender::male); + person* p = 0; + bool mem_error = false; - ps.insert (ps.begin (), p); + do + { + p = new person; + + if (p == 0) + { + mem_error = true; + break; + } + + char* s = strdupx ("Joe"); + + if (s == 0) + { + mem_error = true; + break; + } + + p->first_name (s); + + s = strdupx ("Dirt"); + + if (s == 0) + { + mem_error = true; + break; + } + + p->last_name (s); + + p->age (36); + p->gender (gender::male); + + if (ps.insert (ps.begin (), p) != 0) + { + mem_error = true; + p = 0; // The sequence has already deleted the object. + break; + } + + } while (false); + + if (mem_error) + { + fprintf (stderr, "error: no memory\n"); + delete p; + delete ppl; + return 1; + } } // Serialize. |