Revision 5f28a7bf

View differences:

include/ObjectXML.h
316 316
     */
317 317
    friend std::ostream& operator<<(std::ostream& os, ObjectXML& oxml)
318 318
    {
319
        xmlChar * mem;
320
        int       size;
319
        xmlNodePtr root_node = xmlDocGetRootElement(oxml.xml);
321 320

  
322
        xmlDocDumpMemory(oxml.xml,&mem,&size);
321
        if ( root_node == 0 )
322
        {
323
            return os;
324
        }
325

  
326
        xmlBufferPtr buffer = xmlBufferCreate();
327

  
328
        xmlNodeDump(buffer, oxml.xml, root_node, 0, 0);
323 329

  
324
        std::string str(reinterpret_cast<char *>(mem));
330
        std::string str(reinterpret_cast<char *>(buffer->content));
325 331
        os << str;
326 332

  
327
        xmlFree(mem);
333
        xmlBufferFree(buffer);
328 334

  
329 335
        return os;
330 336
    };
src/vm/History.cc
380 380
    // -------------------------------------------------------------------------
381 381
    ObjectXML::get_nodes("/HISTORY/VM", content);
382 382

  
383
    if (content.empty())
383
    if (!content.empty())
384 384
    {
385
        return -1;
386
    }
385
        ObjectXML vm_info_xml(content[0]);
387 386

  
388
    ObjectXML vm_info_xml(content[0]);
387
        ostringstream oss;
389 388

  
390
    ostringstream oss;
389
        oss << vm_info_xml;
391 390

  
392
    oss << vm_info_xml;
391
        vm_info = oss.str();
393 392

  
394
    vm_info = oss.str();
393
        ObjectXML::free_nodes(content);
395 394

  
396
    ObjectXML::free_nodes(content);
397

  
398
    content.clear();
395
        content.clear();
396
    }
399 397

  
400 398
    non_persistent_data();
401 399

  
src/vm/VirtualMachine.cc
505 505
        return rc;
506 506
    }
507 507

  
508
    //Get History Records. Current history is built in from_xml() (if any).
508
    //Get History Records. 
509 509
    if( hasHistory() )
510 510
    {
511
        last_seq = history->seq - 1;
511
        last_seq = history->seq;
512

  
513
        delete history_records[last_seq];
512 514

  
513 515
        for (int i = last_seq; i >= 0; i--)
514 516
        {
......
526 528

  
527 529
            if ( i == last_seq )
528 530
            {
531
                history = hp;
532
            }
533
            else if ( i == last_seq - 1 )
534
            {
529 535
                previous_history = hp;
530 536
            }
531 537
        }
......
2117 2123
    // -------------------------------------------------------------------------
2118 2124
    // Last history entry
2119 2125
    // -------------------------------------------------------------------------
2120
    ObjectXML::get_nodes("/VM/HISTORY_RECORDS/HISTORY", content);
2126
    int last_seq;
2121 2127

  
2122
    if (!content.empty())
2128
    if ( xpath(last_seq,"/VM/HISTORY_RECORDS/HISTORY/SEQ", -1) == 0 && 
2129
            last_seq != -1 )
2123 2130
    {
2124
        history = new History(oid);
2125
        rc += history->from_xml_node(content[0]);
2131
        history = new History(oid, last_seq);
2126 2132

  
2127 2133
        history_records.resize(history->seq + 1);
2128 2134
        history_records[history->seq] = history;
2129

  
2130
        ObjectXML::free_nodes(content);
2131
        content.clear();
2132 2135
    }
2133 2136

  
2134 2137
    // -------------------------------------------------------------------------

Also available in: Unified diff