]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
added knownstrings_freeable array to prog struct so that attempts to free engine...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 29 Jun 2005 22:45:28 +0000 (22:45 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 29 Jun 2005 22:45:28 +0000 (22:45 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5473 d7cf8633-e32d-0410-b094-e92efae38249

progsvm.h
prvm_edict.c

index 077058bc4de8090225b5e0126e87a93383ab9d48..0884945840ba62a1d5a555b6c734056767b16527 100644 (file)
--- a/progsvm.h
+++ b/progsvm.h
@@ -274,6 +274,7 @@ typedef struct prvm_prog_s
        // (simple optimization of the free string search)
        int                                     firstfreeknownstring;
        const char                      **knownstrings;
+       qbyte                           *knownstrings_freeable;
        const char                      ***stringshash;
 
        // all memory allocations related to this vm_prog (code, edicts, strings)
index b570198c140d2a9c8189fd1b6b6e22d11872e7db..e1143248971b26b71c897d8491945bb256290c3e 100644 (file)
@@ -1313,6 +1313,7 @@ void PRVM_LoadProgs (const char * filename, int numrequiredfunc, char **required
        prog->numknownstrings = 0;
        prog->maxknownstrings = 0;
        prog->knownstrings = NULL;
+       prog->knownstrings_freeable = NULL;
 
        prog->globaldefs = (ddef_t *)((qbyte *)prog->progs + prog->progs->ofs_globaldefs);
 
@@ -1880,10 +1881,15 @@ int PRVM_SetEngineString(const char *s)
                if (i >= prog->maxknownstrings)
                {
                        const char **oldstrings = prog->knownstrings;
+                       const qbyte *oldstrings_freeable = prog->knownstrings_freeable;
                        prog->maxknownstrings += 128;
                        prog->knownstrings = PRVM_Alloc(prog->maxknownstrings * sizeof(char *));
+                       prog->knownstrings_freeable = PRVM_Alloc(prog->maxknownstrings * sizeof(qbyte));
                        if (prog->numknownstrings)
+                       {
                                memcpy((char **)prog->knownstrings, oldstrings, prog->numknownstrings * sizeof(char *));
+                               memcpy((char **)prog->knownstrings_freeable, oldstrings_freeable, prog->numknownstrings * sizeof(qbyte));
+                       }
                }
                prog->numknownstrings++;
        }
@@ -1905,15 +1911,21 @@ int PRVM_AllocString(int bufferlength, char **pointer)
                if (i >= prog->maxknownstrings)
                {
                        const char **oldstrings = prog->knownstrings;
+                       const qbyte *oldstrings_freeable = prog->knownstrings_freeable;
                        prog->maxknownstrings += 128;
                        prog->knownstrings = PRVM_Alloc(prog->maxknownstrings * sizeof(char *));
+                       prog->knownstrings_freeable = PRVM_Alloc(prog->maxknownstrings * sizeof(qbyte));
                        if (prog->numknownstrings)
+                       {
                                memcpy((char **)prog->knownstrings, oldstrings, prog->numknownstrings * sizeof(char *));
+                               memcpy((char **)prog->knownstrings_freeable, oldstrings_freeable, prog->numknownstrings * sizeof(qbyte));
+                       }
                }
                prog->numknownstrings++;
        }
        prog->firstfreeknownstring = i + 1;
        prog->knownstrings[i] = PRVM_Alloc(bufferlength);
+       prog->knownstrings_freeable[i] = true;
        if (pointer)
                *pointer = (char *)(prog->knownstrings[i]);
        return -1 - i;
@@ -1930,8 +1942,11 @@ void PRVM_FreeString(int num)
                num = -1 - num;
                if (!prog->knownstrings[num])
                        PRVM_ERROR("PRVM_FreeString: attempt to free a non-existent or already freed string\n");
+               if (!prog->knownstrings[num])
+                       PRVM_ERROR("PRVM_FreeString: attempt to free a string owned by the engine\n");
                PRVM_Free((char *)prog->knownstrings[num]);
                prog->knownstrings[num] = NULL;
+               prog->knownstrings_freeable[num] = false;
                prog->firstfreeknownstring = min(prog->firstfreeknownstring, num);
        }
        else