Bug Hunting Session
Bug 39236 - EDITING Calc crashes when deleting a sheet with a pivot table on it
Summary: EDITING Calc crashes when deleting a sheet with a pivot table on it
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
3.4.1 release
Hardware: x86 (IA32) All
: medium critical
Assignee: Kohei Yoshida
URL:
Whiteboard: target:3.4.2
Keywords:
Depends on:
Blocks: mab3.4
  Show dependency treegraph
 
Reported: 2011-07-14 13:15 UTC by Phil
Modified: 2013-11-24 21:56 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Crash Log (4.15 KB, text/plain)
2011-07-14 13:15 UTC, Phil
Details
Sample, see Comment 3 (22.19 KB, application/vnd.oasis.opendocument.spreadsheet)
2011-07-15 01:29 UTC, Rainer Bielefeld Retired
Details
Example Spreadsheet (14.12 KB, application/vnd.oasis.opendocument.spreadsheet)
2011-07-15 05:27 UTC, Phil
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Phil 2011-07-14 13:15:24 UTC
Created attachment 49107 [details]
Crash Log

I can consistently get Calc to crash by adding a pivot table to a new sheet, then adding another pivot table to second sheet and then trying to delete the first sheet.

It doesn't matter if I select the PVT destination manually or use the -new sheet- selection.  Once that second pivot table has been created it is impossible to delete the first worksheet and save.  The document recovers fine but the sheet can still not be deleted.

Deleting the pivot table before trying to delete the sheet will allow the sheet to be deleted but then Calc crashes when trying to save.

Problem exists on Windows too.  Didn't try Linux.
Comment 1 Jeffrey 2011-07-14 20:07:20 UTC
Reproduced on LibreOffice 3.4  340m1(Build:103) for OpenSuse Linux.

Confirmed on Linux.

I randomly created two pivot tables, first one based off sheet 1 data, second one based off sheet 2 data. I can delete sheet 2, sheet 2 pivot table fine, and sheet 1 pivot table fine, but when I delete sheet 1, the crash occurs.

But after I have recovered the spreadsheet, I can delete any of the sheets freely without any crash occurring. It seems that the problem is a bit erratic and I will look into it further.

Phil, could you provide an attachment of a spreadsheet in which you have verified the crash? That would make it a lot easier having a "valid" pivot table to work with. Thanks.
Comment 2 Jeffrey 2011-07-14 20:14:19 UTC
Now when I created a new document and created two new pivot tables, after deleting the second sheet, first sheet, and first pivot table, deleting the second pivot table causes Calc to crash. After recovering the document, I can delete all four. The problem does seem erratic to me and impossible to pinpoint, other than knowing that when deleting sheets with pivot tables, chances are LO might crash.
Comment 3 Rainer Bielefeld Retired 2011-07-15 01:27:45 UTC
I can't reproduce a simple problem "Crash when delete sheet with pivot table on it.

BUT:

[Reproducible] with attached "sample_02neu_crashes.ods" and "LibreOffice 3.4.1  - WIN7  Home Premium (64bit) German UI [OOO340m1 (Build:103)]", I can't tell whether that's exactly the reported problem, but may be a related one?

Steps to reproduce
1. Download and open attached "sample_02neu_crashes.ods"
2. Go to Sheet3 (click Tab)
3. Delete one by one from context menu after right click on Sheet Tab:
   Sheet3, sheet2, Pivot Table_Sheet_1_1
4.  Go to Sheet1 (click Tab)
5. Delete Sheet1 from context menu after right click on Sheet Tab
   Expected: sheet will be deleted or at least a warning that you delete
             source for a Pivot table
   Actual: Crash

It would be useful if someone would confirm this behavior before I assign this bug.

@Phil:
Is this your bug? If not, I recommend that you open a new one with sample document and mor detailed desciption
Comment 4 Rainer Bielefeld Retired 2011-07-15 01:29:27 UTC
Created attachment 49124 [details]
Sample, see Comment 3
Comment 5 Phil 2011-07-15 05:27:57 UTC
Created attachment 49136 [details]
Example Spreadsheet

If I open the attached spreadsheet (MAC OSX 10.6, Intel, LO 3.4.1) and try to delete the sheet "Pivot Table_Sheet_1" LO will crash.
Comment 6 Rainer Bielefeld Retired 2011-07-15 11:13:41 UTC
The latest test document does not have such sheet "Pivot Table_Sheet_1". But when I first delete "Pivot Table_Sheet1_1" and then "Pivot Table_Sheet1_2" I get the crash with version from Comment 3 and also with Master "LibO-dev 3.4.5  – WIN7  Home Premium  (64bit) English UI 
[(Build ID:d337f79-a24c961-2865670-9752b71-7f8fd43
	2fdd60d-fd28b6a-fd7bf20-aa369cb-28da3fb
	6a9633a-931d089-ecd263f-c9b55e9-b31b807
	82ff335-599f7e9-bc6a545-1926fdf)]"

Delete sheet with Pivot is a very basic, so crash -> Critical and "Most annoying" 

@Kohei:
Please feel free to reassign if it's not your area!
Comment 7 Kohei Yoshida 2011-07-19 09:42:53 UTC
Ok.  I really struggled with this one since the reason why the crash occurs was not obvious to me just by looking at this code


void ScDPCollection::DeleteOnTab( SCTAB nTab )
{
    maTables.erase(
        remove_if(maTables.begin(), maTables.end(), MatchByTable(nTab)),
        maTables.end());
}

which (is supposed to) delete the data pilot instances whose output live on the sheet being deleted (specified by nTab index).  And maTables is a container of pointers pointing to the data pilot instances (boost::ptr_vector).

But this causes a double-delete, and it was by design as I just found out.  For those of you who are curious, turn to Item 33 of Effective STL by Scott Meyers.

Now that I know the "why", I'll try to come up with a fix soon.
Comment 8 Kohei Yoshida 2011-07-19 12:09:52 UTC
Fixed on master

http://cgit.freedesktop.org/libreoffice/calc/commit/?id=8da78944e7c4fcae9ae40bea7162898d20db6329

The patch is being reviewed on the mailing list for 3.4.2 inclusion.
Comment 9 Kohei Yoshida 2011-07-22 07:58:23 UTC
Unfortunately the fix missed the boat for 3.4.2.  So it will have to wait until 3.4.3, which is actually only a month away.
Comment 10 gibi 2011-07-22 12:33:42 UTC
Waiting for this correction before deploying in professionnal environnements so I'll be glad to check it and test it when 3.4.3rc1 is up! :-)
Thanks Kohei.
Comment 11 Petr Mladek 2011-07-25 10:07:13 UTC
we needed 3.4.2-rc3 and added this fix there.